﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
using Microsoft.Xna.Framework;
using Terraria.DataStructures;
using Terraria.GameContent;
using Terraria.Graphics;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.Utilities;

namespace Terraria
{
	// Token: 0x02000020 RID: 32
	public class Lighting
	{
		// Token: 0x17000034 RID: 52
		// (get) Token: 0x0600017E RID: 382 RVA: 0x00007010 File Offset: 0x00005210
		public static bool NotRetro
		{
			get
			{
				return Lighting.lightMode < 2;
			}
		}

		// Token: 0x17000035 RID: 53
		// (get) Token: 0x0600017F RID: 383 RVA: 0x0000701A File Offset: 0x0000521A
		public static bool UpdateEveryFrame
		{
			get
			{
				return Main.LightingEveryFrame && !Main.RenderTargetsRequired && !Lighting.NotRetro;
			}
		}

		// Token: 0x17000036 RID: 54
		// (get) Token: 0x06000180 RID: 384 RVA: 0x00007034 File Offset: 0x00005234
		public static bool LightingDrawToScreen
		{
			get
			{
				return Main.drawToScreen;
			}
		}

		// Token: 0x06000181 RID: 385 RVA: 0x00087F48 File Offset: 0x00086148
		public static void Initialize(bool resize = false)
		{
			if (!resize)
			{
				Lighting.tempLights = new Dictionary<Point16, Lighting.ColorTriplet>();
				Lighting.swipe = new Lighting.LightingSwipeData();
				Lighting.countdown = new CountdownEvent(0);
				Lighting.threadSwipes = new Lighting.LightingSwipeData[Environment.ProcessorCount];
				for (int i = 0; i < Lighting.threadSwipes.Length; i++)
				{
					Lighting.threadSwipes[i] = new Lighting.LightingSwipeData();
				}
			}
			int num = Main.screenWidth / 16 + Lighting.offScreenTiles * 2 + 10;
			int num2 = Main.screenHeight / 16 + Lighting.offScreenTiles * 2 + 10;
			if (Lighting.states == null || Lighting.states.Length < num || Lighting.states[0].Length < num2)
			{
				Lighting.states = new Lighting.LightingState[num][];
				Lighting.axisFlipStates = new Lighting.LightingState[num2][];
				for (int j = 0; j < num2; j++)
				{
					Lighting.axisFlipStates[j] = new Lighting.LightingState[num];
				}
				for (int k = 0; k < num; k++)
				{
					Lighting.LightingState[] array = new Lighting.LightingState[num2];
					for (int l = 0; l < num2; l++)
					{
						Lighting.LightingState lightingState = new Lighting.LightingState();
						array[l] = lightingState;
						Lighting.axisFlipStates[l][k] = lightingState;
					}
					Lighting.states[k] = array;
				}
			}
		}

		// Token: 0x06000182 RID: 386 RVA: 0x00088068 File Offset: 0x00086268
		public static void LightTiles(int firstX, int lastX, int firstY, int lastY)
		{
			Main.render = true;
			Lighting.oldSkyColor = Lighting.skyColor;
			float num = (float)Main.tileColor.R / 255f;
			float num2 = (float)Main.tileColor.G / 255f;
			float num3 = (float)Main.tileColor.B / 255f;
			Lighting.skyColor = (num + num2 + num3) / 3f;
			if (Lighting.lightMode < 2)
			{
				Lighting.brightness = 1.2f;
				Lighting.offScreenTiles2 = 34;
				Lighting.offScreenTiles = 40;
			}
			else
			{
				Lighting.brightness = 1f;
				Lighting.offScreenTiles2 = 18;
				Lighting.offScreenTiles = 23;
			}
			Lighting.brightness = 1.2f;
			if (Main.player[Main.myPlayer].blind)
			{
				Lighting.brightness = 1f;
			}
			Lighting.defBrightness = Lighting.brightness;
			Lighting.firstTileX = firstX;
			Lighting.lastTileX = lastX;
			Lighting.firstTileY = firstY;
			Lighting.lastTileY = lastY;
			Lighting.firstToLightX = Lighting.firstTileX - Lighting.offScreenTiles;
			Lighting.firstToLightY = Lighting.firstTileY - Lighting.offScreenTiles;
			Lighting.lastToLightX = Lighting.lastTileX + Lighting.offScreenTiles;
			Lighting.lastToLightY = Lighting.lastTileY + Lighting.offScreenTiles;
			Lighting.lightCounter++;
			Main.renderCount++;
			int num4 = Main.screenWidth / 16 + Lighting.offScreenTiles * 2;
			int num5 = Main.screenHeight / 16 + Lighting.offScreenTiles * 2;
			Vector2 vector = Main.screenLastPosition;
			if (Main.renderCount < 3)
			{
				Lighting.doColors();
			}
			if (Main.renderCount == 2)
			{
				vector = Main.screenPosition;
				int num6 = (int)Math.Floor((double)(Main.screenPosition.X / 16f)) - Lighting.scrX;
				int num7 = (int)Math.Floor((double)(Main.screenPosition.Y / 16f)) - Lighting.scrY;
				if (num6 > 16)
				{
					num6 = 0;
				}
				if (num7 > 16)
				{
					num7 = 0;
				}
				int num8 = 0;
				int num9 = num4;
				int num10 = 0;
				int num11 = num5;
				if (num6 < 0)
				{
					num8 -= num6;
				}
				else
				{
					num9 -= num6;
				}
				if (num7 < 0)
				{
					num10 -= num7;
				}
				else
				{
					num11 -= num7;
				}
				if (Lighting.RGB)
				{
					int num12 = num4;
					if (Lighting.states.Length <= num12 + num6)
					{
						num12 = Lighting.states.Length - num6 - 1;
					}
					for (int i = num8; i < num12; i++)
					{
						Lighting.LightingState[] array = Lighting.states[i];
						Lighting.LightingState[] array2 = Lighting.states[i + num6];
						int num13 = num11;
						if (array2.Length <= num13 + num6)
						{
							num13 = array2.Length - num7 - 1;
						}
						for (int j = num10; j < num13; j++)
						{
							Lighting.LightingState lightingState = array[j];
							Lighting.LightingState lightingState2 = array2[j + num7];
							lightingState.r = lightingState2.r2;
							lightingState.g = lightingState2.g2;
							lightingState.b = lightingState2.b2;
						}
					}
				}
				else
				{
					int num14 = num9;
					if (Lighting.states.Length <= num14 + num6)
					{
						num14 = Lighting.states.Length - num6 - 1;
					}
					for (int k = num8; k < num14; k++)
					{
						Lighting.LightingState[] array3 = Lighting.states[k];
						Lighting.LightingState[] array4 = Lighting.states[k + num6];
						int num15 = num11;
						if (array4.Length <= num15 + num6)
						{
							num15 = array4.Length - num7 - 1;
						}
						for (int l = num10; l < num15; l++)
						{
							Lighting.LightingState lightingState3 = array3[l];
							Lighting.LightingState lightingState4 = array4[l + num7];
							lightingState3.r = lightingState4.r2;
							lightingState3.g = lightingState4.r2;
							lightingState3.b = lightingState4.r2;
						}
					}
				}
			}
			else if (!Main.renderNow)
			{
				int num16 = (int)Math.Floor((double)(Main.screenPosition.X / 16f)) - (int)Math.Floor((double)(vector.X / 16f));
				if (num16 > 5 || num16 < -5)
				{
					num16 = 0;
				}
				int num17;
				int num18;
				int num19;
				if (num16 < 0)
				{
					num17 = -1;
					num16 *= -1;
					num18 = num4;
					num19 = num16;
				}
				else
				{
					num17 = 1;
					num18 = 0;
					num19 = num4 - num16;
				}
				int num20 = (int)Math.Floor((double)(Main.screenPosition.Y / 16f)) - (int)Math.Floor((double)(vector.Y / 16f));
				if (num20 > 5 || num20 < -5)
				{
					num20 = 0;
				}
				int num21;
				int num22;
				int num23;
				if (num20 < 0)
				{
					num21 = -1;
					num20 *= -1;
					num22 = num5;
					num23 = num20;
				}
				else
				{
					num21 = 1;
					num22 = 0;
					num23 = num5 - num20;
				}
				if (num16 != 0 || num20 != 0)
				{
					for (int num24 = num18; num24 != num19; num24 += num17)
					{
						Lighting.LightingState[] array5 = Lighting.states[num24];
						Lighting.LightingState[] array6 = Lighting.states[num24 + num16 * num17];
						for (int num25 = num22; num25 != num23; num25 += num21)
						{
							Lighting.LightingState lightingState5 = array5[num25];
							Lighting.LightingState lightingState6 = array6[num25 + num20 * num21];
							lightingState5.r = lightingState6.r;
							lightingState5.g = lightingState6.g;
							lightingState5.b = lightingState6.b;
						}
					}
				}
				if (Netplay.Connection.StatusMax > 0)
				{
					Main.mapTime = 1;
				}
				if (Main.mapTime == 0 && Main.mapEnabled && Main.renderCount == 3)
				{
					try
					{
						Main.mapTime = Main.mapTimeMax;
						Main.updateMap = true;
						Main.mapMinX = Utils.Clamp<int>(Lighting.firstToLightX + Lighting.offScreenTiles, 0, Main.maxTilesX - 1);
						Main.mapMaxX = Utils.Clamp<int>(Lighting.lastToLightX - Lighting.offScreenTiles, 0, Main.maxTilesX - 1);
						Main.mapMinY = Utils.Clamp<int>(Lighting.firstToLightY + Lighting.offScreenTiles, 0, Main.maxTilesY - 1);
						Main.mapMaxY = Utils.Clamp<int>(Lighting.lastToLightY - Lighting.offScreenTiles, 0, Main.maxTilesY - 1);
						for (int m = Main.mapMinX; m < Main.mapMaxX; m++)
						{
							Lighting.LightingState[] array7 = Lighting.states[m - Lighting.firstTileX + Lighting.offScreenTiles];
							for (int n = Main.mapMinY; n < Main.mapMaxY; n++)
							{
								Lighting.LightingState lightingState7 = array7[n - Lighting.firstTileY + Lighting.offScreenTiles];
								Tile tile = Main.tile[m, n];
								float num26 = 0f;
								if (lightingState7.r > num26)
								{
									num26 = lightingState7.r;
								}
								if (lightingState7.g > num26)
								{
									num26 = lightingState7.g;
								}
								if (lightingState7.b > num26)
								{
									num26 = lightingState7.b;
								}
								if (Lighting.lightMode < 2)
								{
									num26 *= 1.5f;
								}
								byte b = (byte)Math.Min(255f, num26 * 255f);
								if ((double)n < Main.worldSurface && !tile.active() && tile.wall == 0 && tile.liquid == 0)
								{
									b = 22;
								}
								if (b > 18 || Main.Map[m, n].Light > 0)
								{
									if (b < 22)
									{
										b = 22;
									}
									Main.Map.UpdateLighting(m, n, b);
								}
							}
						}
					}
					catch
					{
					}
				}
				if (Lighting.oldSkyColor != Lighting.skyColor)
				{
					int num27 = Utils.Clamp<int>(Lighting.firstToLightX, 0, Main.maxTilesX - 1);
					int num28 = Utils.Clamp<int>(Lighting.lastToLightX, 0, Main.maxTilesX - 1);
					int num29 = Utils.Clamp<int>(Lighting.firstToLightY, 0, Main.maxTilesY - 1);
					int num30 = Utils.Clamp<int>(Lighting.lastToLightY, 0, (int)Main.worldSurface - 1);
					if ((double)num29 < Main.worldSurface)
					{
						for (int num31 = num27; num31 < num28; num31++)
						{
							Lighting.LightingState[] array8 = Lighting.states[num31 - Lighting.firstToLightX];
							for (int num32 = num29; num32 < num30; num32++)
							{
								Lighting.LightingState lightingState8 = array8[num32 - Lighting.firstToLightY];
								Tile tile2 = Main.tile[num31, num32];
								if (tile2 == null)
								{
									tile2 = new Tile();
									Main.tile[num31, num32] = tile2;
								}
								if ((!tile2.active() || !Main.tileNoSunLight[(int)tile2.type]) && lightingState8.r < Lighting.skyColor && tile2.liquid < 200 && (Main.wallLight[(int)tile2.wall] || tile2.wall == 73))
								{
									lightingState8.r = num;
									if (lightingState8.g < Lighting.skyColor)
									{
										lightingState8.g = num2;
									}
									if (lightingState8.b < Lighting.skyColor)
									{
										lightingState8.b = num3;
									}
								}
							}
						}
					}
				}
			}
			else
			{
				Lighting.lightCounter = 0;
			}
			if (Main.renderCount > Lighting.maxRenderCount)
			{
				Lighting.PreRenderPhase();
			}
		}

		// Token: 0x06000183 RID: 387 RVA: 0x000888DC File Offset: 0x00086ADC
		public static void PreRenderPhase()
		{
			float num = (float)Main.tileColor.R / 255f;
			float num2 = (float)Main.tileColor.G / 255f;
			float num3 = (float)Main.tileColor.B / 255f;
			Stopwatch stopwatch = new Stopwatch();
			stopwatch.Start();
			int num4 = 0;
			int num5 = Main.screenWidth / 16 + Lighting.offScreenTiles * 2 + 10;
			int num6 = 0;
			int num7 = Main.screenHeight / 16 + Lighting.offScreenTiles * 2 + 10;
			Lighting.minX = num5;
			Lighting.maxX = num4;
			Lighting.minY = num7;
			Lighting.maxY = num6;
			if (Lighting.lightMode == 0 || Lighting.lightMode == 3)
			{
				Lighting.RGB = true;
			}
			else
			{
				Lighting.RGB = false;
			}
			int num8;
			for (int i = num4; i < num5; i = num8 + 1)
			{
				Lighting.LightingState[] array = Lighting.states[i];
				for (int j = num6; j < num7; j = num8 + 1)
				{
					Lighting.LightingState lightingState = array[j];
					lightingState.r2 = 0f;
					lightingState.g2 = 0f;
					lightingState.b2 = 0f;
					lightingState.stopLight = false;
					lightingState.wetLight = false;
					lightingState.honeyLight = false;
					num8 = j;
				}
				num8 = i;
			}
			if (Main.wof >= 0 && Main.player[Main.myPlayer].gross)
			{
				try
				{
					int num9 = (int)Main.screenPosition.Y / 16 - 10;
					int num10 = (int)(Main.screenPosition.Y + (float)Main.screenHeight) / 16 + 10;
					int num11 = (int)Main.npc[Main.wof].position.X / 16;
					if (Main.npc[Main.wof].direction > 0)
					{
						num11 -= 3;
					}
					else
					{
						num11 += 2;
					}
					int num12 = num11 + 8;
					float num13 = 0.5f * Main.demonTorch + 1f * (1f - Main.demonTorch);
					float num14 = 0.3f;
					float num15 = 1f * Main.demonTorch + 0.5f * (1f - Main.demonTorch);
					num13 *= 0.2f;
					num14 *= 0.1f;
					num15 *= 0.3f;
					for (int k = num11; k <= num12; k = num8 + 1)
					{
						Lighting.LightingState[] array2 = Lighting.states[k - num11];
						for (int l = num9; l <= num10; l = num8 + 1)
						{
							Lighting.LightingState lightingState2 = array2[l - Lighting.firstToLightY];
							if (lightingState2.r2 < num13)
							{
								lightingState2.r2 = num13;
							}
							if (lightingState2.g2 < num14)
							{
								lightingState2.g2 = num14;
							}
							if (lightingState2.b2 < num15)
							{
								lightingState2.b2 = num15;
							}
							num8 = l;
						}
						num8 = k;
					}
				}
				catch
				{
				}
			}
			Main.sandTiles = 0;
			Main.evilTiles = 0;
			Main.bloodTiles = 0;
			Main.shroomTiles = 0;
			Main.snowTiles = 0;
			Main.holyTiles = 0;
			Main.meteorTiles = 0;
			Main.jungleTiles = 0;
			Main.dungeonTiles = 0;
			Main.campfire = false;
			Main.sunflower = false;
			Main.starInBottle = false;
			Main.heartLantern = false;
			Main.campfire = false;
			Main.clock = false;
			Main.musicBox = -1;
			Main.waterCandles = 0;
			for (int m = 0; m < Main.player[Main.myPlayer].NPCBannerBuff.Length; m = num8 + 1)
			{
				Main.player[Main.myPlayer].NPCBannerBuff[m] = false;
				num8 = m;
			}
			Main.player[Main.myPlayer].hasBanner = false;
			WorldHooks.ResetNearbyTileEffects();
			int[] screenTileCounts = Main.screenTileCounts;
			Array.Clear(screenTileCounts, 0, screenTileCounts.Length);
			num4 = Utils.Clamp<int>(Lighting.firstToLightX, 5, Main.maxTilesX - 1);
			num5 = Utils.Clamp<int>(Lighting.lastToLightX, 5, Main.maxTilesX - 1);
			num6 = Utils.Clamp<int>(Lighting.firstToLightY, 5, Main.maxTilesY - 1);
			num7 = Utils.Clamp<int>(Lighting.lastToLightY, 5, Main.maxTilesY - 1);
			int num16 = (num5 - num4 - Main.zoneX) / 2;
			int num17 = (num7 - num6 - Main.zoneY) / 2;
			Main.fountainColor = -1;
			Main.monolithType = -1;
			for (int n = num4; n < num5; n = num8 + 1)
			{
				Lighting.LightingState[] array3 = Lighting.states[n - Lighting.firstToLightX];
				for (int num18 = num6; num18 < num7; num18 = num8 + 1)
				{
					Lighting.LightingState lightingState3 = array3[num18 - Lighting.firstToLightY];
					Tile tile = Main.tile[n, num18];
					if (tile == null)
					{
						tile = new Tile();
						Main.tile[n, num18] = tile;
					}
					float num19 = 0f;
					float num20 = 0f;
					float num21 = 0f;
					if ((double)num18 < Main.worldSurface)
					{
						if ((!tile.active() || !Main.tileNoSunLight[(int)tile.type] || ((tile.slope() != 0 || tile.halfBrick()) && Main.tile[n, num18 - 1].liquid == 0 && Main.tile[n, num18 + 1].liquid == 0 && Main.tile[n - 1, num18].liquid == 0 && Main.tile[n + 1, num18].liquid == 0)) && lightingState3.r2 < Lighting.skyColor && (Main.wallLight[(int)tile.wall] || tile.wall == 73 || tile.wall == 227) && tile.liquid < 200 && (!tile.halfBrick() || Main.tile[n, num18 - 1].liquid < 200))
						{
							num19 = num;
							num20 = num2;
							num21 = num3;
						}
						if ((!tile.active() || tile.halfBrick() || !Main.tileNoSunLight[(int)tile.type]) && tile.wall >= 88 && tile.wall <= 93 && tile.liquid < 255)
						{
							num19 = num;
							num20 = num2;
							num21 = num3;
							switch (tile.wall)
							{
							case 88:
								num19 *= 0.9f;
								num20 *= 0.15f;
								num21 *= 0.9f;
								break;
							case 89:
								num19 *= 0.9f;
								num20 *= 0.9f;
								num21 *= 0.15f;
								break;
							case 90:
								num19 *= 0.15f;
								num20 *= 0.15f;
								num21 *= 0.9f;
								break;
							case 91:
								num19 *= 0.15f;
								num20 *= 0.9f;
								num21 *= 0.15f;
								break;
							case 92:
								num19 *= 0.9f;
								num20 *= 0.15f;
								num21 *= 0.15f;
								break;
							case 93:
							{
								float num22 = 0.2f;
								float num23 = 0.7f - num22;
								num19 *= num23 + (float)Main.DiscoR / 255f * num22;
								num20 *= num23 + (float)Main.DiscoG / 255f * num22;
								num21 *= num23 + (float)Main.DiscoB / 255f * num22;
								break;
							}
							}
						}
						if (!Lighting.RGB)
						{
							float num24 = (num19 + num20 + num21) / 3f;
							num19 = (num20 = (num21 = num24));
						}
						if (lightingState3.r2 < num19)
						{
							lightingState3.r2 = num19;
						}
						if (lightingState3.g2 < num20)
						{
							lightingState3.g2 = num20;
						}
						if (lightingState3.b2 < num21)
						{
							lightingState3.b2 = num21;
						}
					}
					float num25 = 0.55f + (float)Math.Sin((double)(Main.GlobalTime * 2f)) * 0.08f;
					if (num18 > Main.maxTilesY - 200)
					{
						if ((!tile.active() || !Main.tileNoSunLight[(int)tile.type] || ((tile.slope() != 0 || tile.halfBrick()) && Main.tile[n, num18 - 1].liquid == 0 && Main.tile[n, num18 + 1].liquid == 0 && Main.tile[n - 1, num18].liquid == 0 && Main.tile[n + 1, num18].liquid == 0)) && lightingState3.r2 < num25 && (Main.wallLight[(int)tile.wall] || tile.wall == 73 || tile.wall == 227) && tile.liquid < 200 && (!tile.halfBrick() || Main.tile[n, num18 - 1].liquid < 200))
						{
							num19 = num25;
							num20 = num25 * 0.6f;
							num21 = num25 * 0.2f;
						}
						if ((!tile.active() || tile.halfBrick() || !Main.tileNoSunLight[(int)tile.type]) && tile.wall >= 88 && tile.wall <= 93 && tile.liquid < 255)
						{
							num19 = num25;
							num20 = num25 * 0.6f;
							num21 = num25 * 0.2f;
							switch (tile.wall)
							{
							case 88:
								num19 *= 0.9f;
								num20 *= 0.15f;
								num21 *= 0.9f;
								break;
							case 89:
								num19 *= 0.9f;
								num20 *= 0.9f;
								num21 *= 0.15f;
								break;
							case 90:
								num19 *= 0.15f;
								num20 *= 0.15f;
								num21 *= 0.9f;
								break;
							case 91:
								num19 *= 0.15f;
								num20 *= 0.9f;
								num21 *= 0.15f;
								break;
							case 92:
								num19 *= 0.9f;
								num20 *= 0.15f;
								num21 *= 0.15f;
								break;
							case 93:
							{
								float num26 = 0.2f;
								float num27 = 0.7f - num26;
								num19 *= num27 + (float)Main.DiscoR / 255f * num26;
								num20 *= num27 + (float)Main.DiscoG / 255f * num26;
								num21 *= num27 + (float)Main.DiscoB / 255f * num26;
								break;
							}
							}
						}
						if (!Lighting.RGB)
						{
							float num28 = (num19 + num20 + num21) / 3f;
							num19 = (num20 = (num21 = num28));
						}
						if (lightingState3.r2 < num19)
						{
							lightingState3.r2 = num19;
						}
						if (lightingState3.g2 < num20)
						{
							lightingState3.g2 = num20;
						}
						if (lightingState3.b2 < num21)
						{
							lightingState3.b2 = num21;
						}
					}
					ushort wall = tile.wall;
					if (wall <= 137)
					{
						if (wall != 33)
						{
							if (wall != 44)
							{
								if (wall == 137 && (!tile.active() || !Main.tileBlockLight[(int)tile.type]))
								{
									float num29 = 0.4f;
									num29 += (float)(270 - (int)Main.mouseTextColor) / 1500f;
									num29 += (float)Main.rand.Next(0, 50) * 0.0005f;
									num19 = 1f * num29;
									num20 = 0.5f * num29;
									num21 = 0.1f * num29;
								}
							}
							else if (!tile.active() || !Main.tileBlockLight[(int)tile.type])
							{
								num19 = (float)Main.DiscoR / 255f * 0.15f;
								num20 = (float)Main.DiscoG / 255f * 0.15f;
								num21 = (float)Main.DiscoB / 255f * 0.15f;
							}
						}
						else if (!tile.active() || !Main.tileBlockLight[(int)tile.type])
						{
							num19 = 0.0899999961f;
							num20 = 0.0525000021f;
							num21 = 0.24f;
						}
					}
					else if (wall <= 166)
					{
						switch (wall)
						{
						case 153:
							num19 = 0.6f;
							num20 = 0.3f;
							break;
						case 154:
							num19 = 0.6f;
							num21 = 0.6f;
							break;
						case 155:
							num19 = 0.6f;
							num20 = 0.6f;
							num21 = 0.6f;
							break;
						case 156:
							num20 = 0.6f;
							break;
						default:
							switch (wall)
							{
							case 164:
								num19 = 0.6f;
								break;
							case 165:
								num21 = 0.6f;
								break;
							case 166:
								num19 = 0.6f;
								num20 = 0.6f;
								break;
							}
							break;
						}
					}
					else
					{
						switch (wall)
						{
						case 174:
							if (!tile.active() || !Main.tileBlockLight[(int)tile.type])
							{
								num19 = 0.2975f;
							}
							break;
						case 175:
							if (!tile.active() || !Main.tileBlockLight[(int)tile.type])
							{
								num19 = 0.075f;
								num20 = 0.15f;
								num21 = 0.4f;
							}
							break;
						case 176:
							if (!tile.active() || !Main.tileBlockLight[(int)tile.type])
							{
								num19 = 0.1f;
								num20 = 0.1f;
								num21 = 0.1f;
							}
							break;
						default:
							if (wall == 182 && (!tile.active() || !Main.tileBlockLight[(int)tile.type]))
							{
								num19 = 0.24f;
								num20 = 0.12f;
								num21 = 0.0899999961f;
							}
							break;
						}
					}
					WallLoader.ModifyLight(n, num18, (int)wall, ref num19, ref num20, ref num21);
					if (tile.active())
					{
						bool closer = false;
						if (n > num4 + num16 && n < num5 - num16 && num18 > num6 + num17 && num18 < num7 - num17)
						{
							int[] array4 = screenTileCounts;
							ushort type = tile.type;
							num8 = array4[(int)type];
							array4[(int)type] = num8 + 1;
							if (tile.type == 215 && tile.frameY < 36)
							{
								Main.campfire = true;
							}
							if (tile.type == 405)
							{
								Main.campfire = true;
							}
							if (tile.type == 42 && tile.frameY >= 324 && tile.frameY <= 358)
							{
								Main.heartLantern = true;
							}
							if (tile.type == 42 && tile.frameY >= 252 && tile.frameY <= 286)
							{
								Main.starInBottle = true;
							}
							if (tile.type == 91 && (tile.frameX >= 396 || tile.frameY >= 54))
							{
								int num30 = (int)(tile.frameX / 18 - 21);
								for (int num31 = (int)tile.frameY; num31 >= 54; num31 -= 54)
								{
									num30 += 90;
									num30 += 21;
								}
								int num32 = Item.BannerToItem(num30);
								if (ItemID.Sets.BannerStrength[num32].Enabled)
								{
									Main.player[Main.myPlayer].NPCBannerBuff[num30] = true;
									Main.player[Main.myPlayer].hasBanner = true;
								}
							}
							closer = true;
						}
						ushort type2 = tile.type;
						if (type2 != 139)
						{
							if (type2 != 207)
							{
								if (type2 == 410 && tile.frameY >= 56)
								{
									int monolithType = (int)(tile.frameX / 36);
									Main.monolithType = monolithType;
								}
							}
							else if (tile.frameY >= 72)
							{
								switch (tile.frameX / 36)
								{
								case 0:
									Main.fountainColor = 0;
									break;
								case 1:
									Main.fountainColor = 6;
									break;
								case 2:
									Main.fountainColor = 3;
									break;
								case 3:
									Main.fountainColor = 5;
									break;
								case 4:
									Main.fountainColor = 2;
									break;
								case 5:
									Main.fountainColor = 10;
									break;
								case 6:
									Main.fountainColor = 4;
									break;
								case 7:
									Main.fountainColor = 9;
									break;
								default:
									Main.fountainColor = -1;
									break;
								}
							}
						}
						else if (tile.frameX >= 36)
						{
							Main.musicBox = (int)(tile.frameY / 36);
						}
						if (TileLoader.IsModMusicBox(tile) && tile.frameX >= 36)
						{
							Main.musicBox = SoundLoader.tileToMusic[(int)tile.type][(int)(tile.frameY / 36 * 36)];
						}
						TileLoader.NearbyEffects(n, num18, (int)type2, closer);
						if (Main.tileBlockLight[(int)tile.type] && (Lighting.lightMode >= 2 || (tile.type != 131 && !tile.inActive() && tile.slope() == 0)))
						{
							lightingState3.stopLight = true;
						}
						if (tile.type == 104)
						{
							Main.clock = true;
						}
						if (Main.tileLighted[(int)tile.type])
						{
							type2 = tile.type;
							if (type2 <= 184)
							{
								if (type2 <= 77)
								{
									if (type2 <= 37)
									{
										if (type2 <= 17)
										{
											if (type2 != 4)
											{
												if (type2 != 17)
												{
													goto IL_349F;
												}
												goto IL_3420;
											}
											else
											{
												if (tile.frameX >= 66)
												{
													goto IL_349F;
												}
												switch (tile.frameY / 22)
												{
												case 0:
													num19 = 1f;
													num20 = 0.95f;
													num21 = 0.8f;
													goto IL_349F;
												case 1:
													num19 = 0f;
													num20 = 0.1f;
													num21 = 1.3f;
													goto IL_349F;
												case 2:
													num19 = 1f;
													num20 = 0.1f;
													num21 = 0.1f;
													goto IL_349F;
												case 3:
													num19 = 0f;
													num20 = 1f;
													num21 = 0.1f;
													goto IL_349F;
												case 4:
													num19 = 0.9f;
													num20 = 0f;
													num21 = 0.9f;
													goto IL_349F;
												case 5:
													num19 = 1.3f;
													num20 = 1.3f;
													num21 = 1.3f;
													goto IL_349F;
												case 6:
													num19 = 0.9f;
													num20 = 0.9f;
													num21 = 0f;
													goto IL_349F;
												case 7:
													num19 = 0.5f * Main.demonTorch + 1f * (1f - Main.demonTorch);
													num20 = 0.3f;
													num21 = 1f * Main.demonTorch + 0.5f * (1f - Main.demonTorch);
													goto IL_349F;
												case 8:
													num19 = 0.85f;
													num20 = 1f;
													num21 = 0.7f;
													goto IL_349F;
												case 9:
													num19 = 0.7f;
													num20 = 0.85f;
													num21 = 1f;
													goto IL_349F;
												case 10:
													num19 = 1f;
													num20 = 0.5f;
													num21 = 0f;
													goto IL_349F;
												case 11:
													num19 = 1.25f;
													num20 = 1.25f;
													num21 = 0.8f;
													goto IL_349F;
												case 12:
													num19 = 0.75f;
													num20 = 1.28249991f;
													num21 = 1.2f;
													goto IL_349F;
												case 13:
													num19 = 0.95f;
													num20 = 0.65f;
													num21 = 1.3f;
													goto IL_349F;
												case 14:
													num19 = (float)Main.DiscoR / 255f;
													num20 = (float)Main.DiscoG / 255f;
													num21 = (float)Main.DiscoB / 255f;
													goto IL_349F;
												case 15:
													num19 = 1f;
													num20 = 0f;
													num21 = 1f;
													goto IL_349F;
												default:
													num19 = 1f;
													num20 = 0.95f;
													num21 = 0.8f;
													goto IL_349F;
												}
											}
										}
										else if (type2 != 22)
										{
											switch (type2)
											{
											case 26:
											case 31:
											{
												if ((tile.type == 31 && tile.frameX >= 36) || (tile.type == 26 && tile.frameX >= 54))
												{
													float num33 = (float)Main.rand.Next(-5, 6) * 0.0025f;
													num19 = 0.5f + num33 * 2f;
													num20 = 0.2f + num33;
													num21 = 0.1f;
													goto IL_349F;
												}
												float num34 = (float)Main.rand.Next(-5, 6) * 0.0025f;
												num19 = 0.31f + num34;
												num20 = 0.1f;
												num21 = 0.44f + num34 * 2f;
												goto IL_349F;
											}
											case 27:
												if (tile.frameY < 36)
												{
													num19 = 0.3f;
													num20 = 0.27f;
													goto IL_349F;
												}
												goto IL_349F;
											case 28:
											case 29:
											case 30:
											case 32:
											case 36:
												goto IL_349F;
											case 33:
												if (tile.frameX == 0)
												{
													int num35 = (int)(tile.frameY / 22);
													if (num35 <= 14)
													{
														switch (num35)
														{
														case 0:
															num19 = 1f;
															num20 = 0.95f;
															num21 = 0.65f;
															goto IL_349F;
														case 1:
															num19 = 0.55f;
															num20 = 0.85f;
															num21 = 0.35f;
															goto IL_349F;
														case 2:
															num19 = 0.65f;
															num20 = 0.95f;
															num21 = 0.5f;
															goto IL_349F;
														case 3:
															num19 = 0.2f;
															num20 = 0.75f;
															num21 = 1f;
															goto IL_349F;
														default:
															if (num35 == 14)
															{
																num19 = 1f;
																num20 = 1f;
																num21 = 0.6f;
																goto IL_349F;
															}
															break;
														}
													}
													else
													{
														switch (num35)
														{
														case 19:
															num19 = 0.37f;
															num20 = 0.8f;
															num21 = 1f;
															goto IL_349F;
														case 20:
															num19 = 0f;
															num20 = 0.9f;
															num21 = 1f;
															goto IL_349F;
														case 21:
															num19 = 0.25f;
															num20 = 0.7f;
															num21 = 1f;
															goto IL_349F;
														case 22:
														case 23:
														case 24:
															break;
														case 25:
															num19 = 0.5f * Main.demonTorch + 1f * (1f - Main.demonTorch);
															num20 = 0.3f;
															num21 = 1f * Main.demonTorch + 0.5f * (1f - Main.demonTorch);
															goto IL_349F;
														default:
															if (num35 == 28)
															{
																num19 = 0.9f;
																num20 = 0.75f;
																num21 = 1f;
																goto IL_349F;
															}
															if (num35 == 30)
															{
																Vector3 vector = Main.hslToRgb(Main.demonTorch * 0.12f + 0.69f, 1f, 0.75f).ToVector3() * 1.2f;
																num19 = vector.X;
																num20 = vector.Y;
																num21 = vector.Z;
																goto IL_349F;
															}
															break;
														}
													}
													num19 = 1f;
													num20 = 0.95f;
													num21 = 0.65f;
													goto IL_349F;
												}
												goto IL_349F;
											case 34:
												if (tile.frameX % 108 < 54)
												{
													int num36 = (int)(tile.frameY / 54);
													switch (num36 + (int)(37 * (tile.frameX / 108)))
													{
													case 7:
														num19 = 0.95f;
														num20 = 0.95f;
														num21 = 0.5f;
														goto IL_349F;
													case 8:
														num19 = 0.85f;
														num20 = 0.6f;
														num21 = 1f;
														goto IL_349F;
													case 9:
														num19 = 1f;
														num20 = 0.6f;
														num21 = 0.6f;
														goto IL_349F;
													case 11:
													case 17:
														num19 = 0.75f;
														num20 = 0.9f;
														num21 = 1f;
														goto IL_349F;
													case 15:
														num19 = 1f;
														num20 = 1f;
														num21 = 0.7f;
														goto IL_349F;
													case 18:
														num19 = 1f;
														num20 = 1f;
														num21 = 0.6f;
														goto IL_349F;
													case 24:
														num19 = 0.37f;
														num20 = 0.8f;
														num21 = 1f;
														goto IL_349F;
													case 25:
														num19 = 0f;
														num20 = 0.9f;
														num21 = 1f;
														goto IL_349F;
													case 26:
														num19 = 0.25f;
														num20 = 0.7f;
														num21 = 1f;
														goto IL_349F;
													case 27:
														num19 = 0.55f;
														num20 = 0.85f;
														num21 = 0.35f;
														goto IL_349F;
													case 28:
														num19 = 0.65f;
														num20 = 0.95f;
														num21 = 0.5f;
														goto IL_349F;
													case 29:
														num19 = 0.2f;
														num20 = 0.75f;
														num21 = 1f;
														goto IL_349F;
													case 32:
														num19 = 0.5f * Main.demonTorch + 1f * (1f - Main.demonTorch);
														num20 = 0.3f;
														num21 = 1f * Main.demonTorch + 0.5f * (1f - Main.demonTorch);
														goto IL_349F;
													case 35:
														num19 = 0.9f;
														num20 = 0.75f;
														num21 = 1f;
														goto IL_349F;
													case 37:
													{
														Vector3 vector2 = Main.hslToRgb(Main.demonTorch * 0.12f + 0.69f, 1f, 0.75f).ToVector3() * 1.2f;
														num19 = vector2.X;
														num20 = vector2.Y;
														num21 = vector2.Z;
														goto IL_349F;
													}
													}
													num19 = 1f;
													num20 = 0.95f;
													num21 = 0.8f;
													goto IL_349F;
												}
												goto IL_349F;
											case 35:
												if (tile.frameX < 36)
												{
													num19 = 0.75f;
													num20 = 0.6f;
													num21 = 0.3f;
													goto IL_349F;
												}
												goto IL_349F;
											case 37:
												num19 = 0.56f;
												num20 = 0.43f;
												num21 = 0.15f;
												goto IL_349F;
											default:
												goto IL_349F;
											}
										}
									}
									else if (type2 <= 49)
									{
										if (type2 != 42)
										{
											if (type2 == 49)
											{
												num19 = 0f;
												num20 = 0.35f;
												num21 = 0.8f;
												goto IL_349F;
											}
											goto IL_349F;
										}
										else
										{
											if (tile.frameX != 0)
											{
												goto IL_349F;
											}
											int num37 = (int)(tile.frameY / 36);
											int num38 = num37;
											switch (num38)
											{
											case 0:
												num19 = 0.7f;
												num20 = 0.65f;
												num21 = 0.55f;
												goto IL_349F;
											case 1:
												num19 = 0.9f;
												num20 = 0.75f;
												num21 = 0.6f;
												goto IL_349F;
											case 2:
												num19 = 0.8f;
												num20 = 0.6f;
												num21 = 0.6f;
												goto IL_349F;
											case 3:
												num19 = 0.65f;
												num20 = 0.5f;
												num21 = 0.2f;
												goto IL_349F;
											case 4:
												num19 = 0.5f;
												num20 = 0.7f;
												num21 = 0.4f;
												goto IL_349F;
											case 5:
												num19 = 0.9f;
												num20 = 0.4f;
												num21 = 0.2f;
												goto IL_349F;
											case 6:
												num19 = 0.7f;
												num20 = 0.75f;
												num21 = 0.3f;
												goto IL_349F;
											case 7:
											{
												float num39 = Main.demonTorch * 0.2f;
												num19 = 0.9f - num39;
												num20 = 0.9f - num39;
												num21 = 0.7f + num39;
												goto IL_349F;
											}
											case 8:
												num19 = 0.75f;
												num20 = 0.6f;
												num21 = 0.3f;
												goto IL_349F;
											case 9:
												num19 = 1f;
												num20 = 0.3f;
												num21 = 0.5f;
												num21 += Main.demonTorch * 0.2f;
												num19 -= Main.demonTorch * 0.1f;
												num20 -= Main.demonTorch * 0.2f;
												goto IL_349F;
											default:
												switch (num38)
												{
												case 28:
													num19 = 0.37f;
													num20 = 0.8f;
													num21 = 1f;
													goto IL_349F;
												case 29:
													num19 = 0f;
													num20 = 0.9f;
													num21 = 1f;
													goto IL_349F;
												case 30:
													num19 = 0.25f;
													num20 = 0.7f;
													num21 = 1f;
													goto IL_349F;
												case 32:
													num19 = 0.5f * Main.demonTorch + 1f * (1f - Main.demonTorch);
													num20 = 0.3f;
													num21 = 1f * Main.demonTorch + 0.5f * (1f - Main.demonTorch);
													goto IL_349F;
												case 35:
													num19 = 0.7f;
													num20 = 0.6f;
													num21 = 0.9f;
													goto IL_349F;
												case 37:
												{
													Vector3 vector3 = Main.hslToRgb(Main.demonTorch * 0.12f + 0.69f, 1f, 0.75f).ToVector3() * 1.2f;
													num19 = vector3.X;
													num20 = vector3.Y;
													num21 = vector3.Z;
													goto IL_349F;
												}
												}
												num19 = 1f;
												num20 = 1f;
												num21 = 1f;
												goto IL_349F;
											}
										}
									}
									else if (type2 != 61)
									{
										if (type2 - 70 <= 2)
										{
											goto IL_3437;
										}
										if (type2 == 77)
										{
											num19 = 0.75f;
											num20 = 0.45f;
											num21 = 0.25f;
											goto IL_349F;
										}
										goto IL_349F;
									}
									else
									{
										if (tile.frameX == 144)
										{
											float num40 = 1f + (float)(270 - (int)Main.mouseTextColor) / 400f;
											float num41 = 0.8f - (float)(270 - (int)Main.mouseTextColor) / 400f;
											num19 = 0.42f * num41;
											num20 = 0.81f * num40;
											num21 = 0.52f * num41;
											goto IL_349F;
										}
										goto IL_349F;
									}
								}
								else
								{
									if (type2 <= 133)
									{
										if (type2 <= 100)
										{
											if (type2 != 83)
											{
												if (type2 != 84)
												{
													switch (type2)
													{
													case 92:
														if (tile.frameY <= 18 && tile.frameX == 0)
														{
															num19 = 1f;
															num20 = 1f;
															num21 = 1f;
															goto IL_349F;
														}
														goto IL_349F;
													case 93:
														if (tile.frameX == 0)
														{
															switch (tile.frameY / 54)
															{
															case 1:
																num19 = 0.95f;
																num20 = 0.95f;
																num21 = 0.5f;
																goto IL_349F;
															case 2:
																num19 = 0.85f;
																num20 = 0.6f;
																num21 = 1f;
																goto IL_349F;
															case 3:
																num19 = 0.75f;
																num20 = 1f;
																num21 = 0.6f;
																goto IL_349F;
															case 4:
															case 5:
																num19 = 0.75f;
																num20 = 0.9f;
																num21 = 1f;
																goto IL_349F;
															case 9:
																num19 = 1f;
																num20 = 1f;
																num21 = 0.7f;
																goto IL_349F;
															case 13:
																num19 = 1f;
																num20 = 1f;
																num21 = 0.6f;
																goto IL_349F;
															case 19:
																num19 = 0.37f;
																num20 = 0.8f;
																num21 = 1f;
																goto IL_349F;
															case 20:
																num19 = 0f;
																num20 = 0.9f;
																num21 = 1f;
																goto IL_349F;
															case 21:
																num19 = 0.25f;
																num20 = 0.7f;
																num21 = 1f;
																goto IL_349F;
															case 23:
																num19 = 0.5f * Main.demonTorch + 1f * (1f - Main.demonTorch);
																num20 = 0.3f;
																num21 = 1f * Main.demonTorch + 0.5f * (1f - Main.demonTorch);
																goto IL_349F;
															case 24:
																num19 = 0.35f;
																num20 = 0.5f;
																num21 = 0.3f;
																goto IL_349F;
															case 25:
																num19 = 0.34f;
																num20 = 0.4f;
																num21 = 0.31f;
																goto IL_349F;
															case 26:
																num19 = 0.25f;
																num20 = 0.32f;
																num21 = 0.5f;
																goto IL_349F;
															case 29:
																num19 = 0.9f;
																num20 = 0.75f;
																num21 = 1f;
																goto IL_349F;
															case 31:
															{
																Vector3 vector4 = Main.hslToRgb(Main.demonTorch * 0.12f + 0.69f, 1f, 0.75f).ToVector3() * 1.2f;
																num19 = vector4.X;
																num20 = vector4.Y;
																num21 = vector4.Z;
																goto IL_349F;
															}
															}
															num19 = 1f;
															num20 = 0.97f;
															num21 = 0.85f;
															goto IL_349F;
														}
														goto IL_349F;
													case 94:
													case 97:
													case 99:
														goto IL_349F;
													case 95:
														if (tile.frameX < 36)
														{
															num19 = 1f;
															num20 = 0.95f;
															num21 = 0.8f;
															goto IL_349F;
														}
														goto IL_349F;
													case 96:
														if (tile.frameX >= 36)
														{
															num19 = 0.5f;
															num20 = 0.35f;
															num21 = 0.1f;
															goto IL_349F;
														}
														goto IL_349F;
													case 98:
														if (tile.frameY == 0)
														{
															num19 = 1f;
															num20 = 0.97f;
															num21 = 0.85f;
															goto IL_349F;
														}
														goto IL_349F;
													case 100:
														break;
													default:
														goto IL_349F;
													}
												}
												else
												{
													int num42 = (int)(tile.frameX / 18);
													if (num42 == 2)
													{
														float num43 = (float)(270 - (int)Main.mouseTextColor) / 800f;
														if (num43 > 1f)
														{
															num43 = 1f;
														}
														else if (num43 < 0f)
														{
															num43 = 0f;
														}
														num19 = num43 * 0.7f;
														num20 = num43;
														num21 = num43 * 0.1f;
														goto IL_349F;
													}
													if (num42 == 5)
													{
														float num44 = 0.9f;
														num19 = num44;
														num20 = num44 * 0.8f;
														num21 = num44 * 0.2f;
														goto IL_349F;
													}
													if (num42 == 6)
													{
														float num45 = 0.08f;
														num20 = num45 * 0.8f;
														num21 = num45;
														goto IL_349F;
													}
													goto IL_349F;
												}
											}
											else
											{
												if (tile.frameX == 18 && !Main.dayTime)
												{
													num19 = 0.1f;
													num20 = 0.4f;
													num21 = 0.6f;
												}
												if (tile.frameX == 90 && !Main.raining && Main.time > 40500.0)
												{
													num19 = 0.9f;
													num20 = 0.72f;
													num21 = 0.18f;
													goto IL_349F;
												}
												goto IL_349F;
											}
										}
										else
										{
											switch (type2)
											{
											case 125:
											{
												float num46 = (float)Main.rand.Next(28, 42) * 0.01f;
												num46 += (float)(270 - (int)Main.mouseTextColor) / 800f;
												num20 = (lightingState3.g2 = 0.3f * num46);
												num21 = (lightingState3.b2 = 0.6f * num46);
												goto IL_349F;
											}
											case 126:
												if (tile.frameX < 36)
												{
													num19 = (float)Main.DiscoR / 255f;
													num20 = (float)Main.DiscoG / 255f;
													num21 = (float)Main.DiscoB / 255f;
													goto IL_349F;
												}
												goto IL_349F;
											case 127:
											case 128:
												goto IL_349F;
											case 129:
												switch (tile.frameX / 18 % 3)
												{
												case 0:
													num19 = 0f;
													num20 = 0.05f;
													num21 = 0.25f;
													goto IL_349F;
												case 1:
													num19 = 0.2f;
													num20 = 0f;
													num21 = 0.15f;
													goto IL_349F;
												case 2:
													num19 = 0.1f;
													num20 = 0f;
													num21 = 0.2f;
													goto IL_349F;
												default:
													goto IL_349F;
												}
												break;
											default:
												if (type2 != 133)
												{
													goto IL_349F;
												}
												goto IL_3420;
											}
										}
									}
									else if (type2 <= 149)
									{
										if (type2 == 140)
										{
											goto IL_28F0;
										}
										if (type2 == 149 && tile.frameX <= 36)
										{
											switch (tile.frameX / 18)
											{
											case 0:
												num19 = 0.1f;
												num20 = 0.2f;
												num21 = 0.5f;
												break;
											case 1:
												num19 = 0.5f;
												num20 = 0.1f;
												num21 = 0.1f;
												break;
											case 2:
												num19 = 0.2f;
												num20 = 0.5f;
												num21 = 0.1f;
												break;
											}
											num19 *= (float)Main.rand.Next(970, 1031) * 0.001f;
											num20 *= (float)Main.rand.Next(970, 1031) * 0.001f;
											num21 *= (float)Main.rand.Next(970, 1031) * 0.001f;
											goto IL_349F;
										}
										goto IL_349F;
									}
									else
									{
										if (type2 == 160)
										{
											num19 = (float)Main.DiscoR / 255f * 0.25f;
											num20 = (float)Main.DiscoG / 255f * 0.25f;
											num21 = (float)Main.DiscoB / 255f * 0.25f;
											goto IL_349F;
										}
										switch (type2)
										{
										case 171:
										{
											int num47 = n;
											int num48 = num18;
											if (tile.frameX < 10)
											{
												num47 -= (int)tile.frameX;
												num48 -= (int)tile.frameY;
											}
											switch ((Main.tile[num47, num48].frameY & 15360) >> 10)
											{
											case 1:
												num19 = 0.1f;
												num20 = 0.1f;
												num21 = 0.1f;
												break;
											case 2:
												num19 = 0.2f;
												break;
											case 3:
												num20 = 0.2f;
												break;
											case 4:
												num21 = 0.2f;
												break;
											case 5:
												num19 = 0.125f;
												num20 = 0.125f;
												break;
											case 6:
												num19 = 0.2f;
												num20 = 0.1f;
												break;
											case 7:
												num19 = 0.125f;
												num20 = 0.125f;
												break;
											case 8:
												num19 = 0.08f;
												num20 = 0.175f;
												break;
											case 9:
												num20 = 0.125f;
												num21 = 0.125f;
												break;
											case 10:
												num19 = 0.125f;
												num21 = 0.125f;
												break;
											case 11:
												num19 = 0.1f;
												num20 = 0.1f;
												num21 = 0.2f;
												break;
											default:
												num19 = (num20 = (num21 = 0f));
												break;
											}
											num19 *= 0.5f;
											num20 *= 0.5f;
											num21 *= 0.5f;
											goto IL_349F;
										}
										case 172:
											goto IL_349F;
										case 173:
											break;
										case 174:
											if (tile.frameX == 0)
											{
												num19 = 1f;
												num20 = 0.95f;
												num21 = 0.65f;
												goto IL_349F;
											}
											goto IL_349F;
										default:
											if (type2 == 184 && tile.frameX == 110)
											{
												num19 = 0.25f;
												num20 = 0.1f;
												num21 = 0f;
												goto IL_349F;
											}
											goto IL_349F;
										}
									}
									if (tile.frameX < 36)
									{
										int num49 = (int)(tile.frameY / 36);
										int num50 = num49;
										switch (num50)
										{
										case 1:
											num19 = 0.95f;
											num20 = 0.95f;
											num21 = 0.5f;
											goto IL_349F;
										case 2:
										case 4:
										case 5:
										case 7:
										case 8:
										case 10:
										case 12:
										case 14:
										case 15:
										case 16:
										case 17:
										case 18:
											break;
										case 3:
											num19 = 1f;
											num20 = 0.6f;
											num21 = 0.6f;
											goto IL_349F;
										case 6:
										case 9:
											num19 = 0.75f;
											num20 = 0.9f;
											num21 = 1f;
											goto IL_349F;
										case 11:
											num19 = 1f;
											num20 = 1f;
											num21 = 0.7f;
											goto IL_349F;
										case 13:
											num19 = 1f;
											num20 = 1f;
											num21 = 0.6f;
											goto IL_349F;
										case 19:
											num19 = 0.37f;
											num20 = 0.8f;
											num21 = 1f;
											goto IL_349F;
										case 20:
											num19 = 0f;
											num20 = 0.9f;
											num21 = 1f;
											goto IL_349F;
										case 21:
											num19 = 0.25f;
											num20 = 0.7f;
											num21 = 1f;
											goto IL_349F;
										case 22:
											num19 = 0.35f;
											num20 = 0.5f;
											num21 = 0.3f;
											goto IL_349F;
										case 23:
											num19 = 0.34f;
											num20 = 0.4f;
											num21 = 0.31f;
											goto IL_349F;
										case 24:
											num19 = 0.25f;
											num20 = 0.32f;
											num21 = 0.5f;
											goto IL_349F;
										case 25:
											num19 = 0.5f * Main.demonTorch + 1f * (1f - Main.demonTorch);
											num20 = 0.3f;
											num21 = 1f * Main.demonTorch + 0.5f * (1f - Main.demonTorch);
											goto IL_349F;
										default:
											if (num50 == 29)
											{
												num19 = 0.9f;
												num20 = 0.75f;
												num21 = 1f;
												goto IL_349F;
											}
											if (num50 == 31)
											{
												Vector3 vector5 = Main.hslToRgb(Main.demonTorch * 0.12f + 0.69f, 1f, 0.75f).ToVector3() * 1.2f;
												num19 = vector5.X;
												num20 = vector5.Y;
												num21 = vector5.Z;
												goto IL_349F;
											}
											break;
										}
										num19 = 1f;
										num20 = 0.95f;
										num21 = 0.65f;
										goto IL_349F;
									}
									goto IL_349F;
								}
								IL_28F0:
								num19 = 0.12f;
								num20 = 0.07f;
								num21 = 0.32f;
								goto IL_349F;
							}
							if (type2 <= 318)
							{
								if (type2 <= 215)
								{
									if (type2 <= 204)
									{
										if (type2 == 190)
										{
											goto IL_3437;
										}
										if (type2 != 204)
										{
											goto IL_349F;
										}
									}
									else if (type2 != 209)
									{
										if (type2 == 215 && tile.frameY < 36)
										{
											float num51 = (float)Main.rand.Next(28, 42) * 0.005f;
											num51 += (float)(270 - (int)Main.mouseTextColor) / 700f;
											switch (tile.frameX / 54)
											{
											case 1:
												num19 = 0.7f;
												num20 = 1f;
												num21 = 0.5f;
												break;
											case 2:
												num19 = 0.5f * Main.demonTorch + 1f * (1f - Main.demonTorch);
												num20 = 0.3f;
												num21 = 1f * Main.demonTorch + 0.5f * (1f - Main.demonTorch);
												break;
											case 3:
												num19 = 0.45f;
												num20 = 0.75f;
												num21 = 1f;
												break;
											case 4:
												num19 = 1.15f;
												num20 = 1.15f;
												num21 = 0.5f;
												break;
											case 5:
												num19 = (float)Main.DiscoR / 255f;
												num20 = (float)Main.DiscoG / 255f;
												num21 = (float)Main.DiscoB / 255f;
												break;
											case 6:
												num19 = 0.75f;
												num20 = 1.28249991f;
												num21 = 1.2f;
												break;
											case 7:
												num19 = 0.95f;
												num20 = 0.65f;
												num21 = 1.3f;
												break;
											default:
												num19 = 0.9f;
												num20 = 0.3f;
												num21 = 0.1f;
												break;
											}
											num19 += num51;
											num20 += num51;
											num21 += num51;
											goto IL_349F;
										}
										goto IL_349F;
									}
									else
									{
										if (tile.frameX == 234 || tile.frameX == 252)
										{
											Vector3 vector6 = PortalHelper.GetPortalColor(Main.myPlayer, 0).ToVector3() * 0.65f;
											num19 = vector6.X;
											num20 = vector6.Y;
											num21 = vector6.Z;
											goto IL_349F;
										}
										if (tile.frameX == 306 || tile.frameX == 324)
										{
											Vector3 vector7 = PortalHelper.GetPortalColor(Main.myPlayer, 1).ToVector3() * 0.65f;
											num19 = vector7.X;
											num20 = vector7.Y;
											num21 = vector7.Z;
											goto IL_349F;
										}
										goto IL_349F;
									}
								}
								else if (type2 <= 271)
								{
									switch (type2)
									{
									case 235:
										if ((double)lightingState3.r2 < 0.6)
										{
											lightingState3.r2 = 0.6f;
										}
										if ((double)lightingState3.g2 < 0.6)
										{
											lightingState3.g2 = 0.6f;
											goto IL_349F;
										}
										goto IL_349F;
									case 236:
										goto IL_349F;
									case 237:
										num19 = 0.1f;
										num20 = 0.1f;
										goto IL_349F;
									case 238:
										if ((double)lightingState3.r2 < 0.5)
										{
											lightingState3.r2 = 0.5f;
										}
										if ((double)lightingState3.b2 < 0.5)
										{
											lightingState3.b2 = 0.5f;
											goto IL_349F;
										}
										goto IL_349F;
									default:
										switch (type2)
										{
										case 262:
											num19 = 0.75f;
											num21 = 0.75f;
											goto IL_349F;
										case 263:
											num19 = 0.75f;
											num20 = 0.75f;
											goto IL_349F;
										case 264:
											num21 = 0.75f;
											goto IL_349F;
										case 265:
											num20 = 0.75f;
											goto IL_349F;
										case 266:
											num19 = 0.75f;
											goto IL_349F;
										case 267:
											num19 = 0.75f;
											num20 = 0.75f;
											num21 = 0.75f;
											goto IL_349F;
										case 268:
											num19 = 0.75f;
											num20 = 0.375f;
											goto IL_349F;
										case 269:
											goto IL_349F;
										case 270:
											num19 = 0.73f;
											num20 = 1f;
											num21 = 0.41f;
											goto IL_349F;
										case 271:
											num19 = 0.45f;
											num20 = 0.95f;
											num21 = 1f;
											goto IL_349F;
										default:
											goto IL_349F;
										}
										break;
									}
								}
								else
								{
									if (type2 == 286)
									{
										num19 = 0.1f;
										num20 = 0.2f;
										num21 = 0.7f;
										goto IL_349F;
									}
									if (type2 == 302)
									{
										goto IL_3420;
									}
									if (type2 - 316 > 2)
									{
										goto IL_349F;
									}
									int num52 = n - (int)(tile.frameX / 18);
									int num53 = num18 - (int)(tile.frameY / 18);
									int num54 = num52 / 2 * (num53 / 3);
									num54 %= Main.cageFrames;
									bool flag = Main.jellyfishCageMode[(int)(tile.type - 316), num54] == 2;
									if (tile.type == 316)
									{
										if (flag)
										{
											num19 = 0.2f;
											num20 = 0.3f;
											num21 = 0.8f;
										}
										else
										{
											num19 = 0.1f;
											num20 = 0.2f;
											num21 = 0.5f;
										}
									}
									if (tile.type == 317)
									{
										if (flag)
										{
											num19 = 0.2f;
											num20 = 0.7f;
											num21 = 0.3f;
										}
										else
										{
											num19 = 0.05f;
											num20 = 0.45f;
											num21 = 0.1f;
										}
									}
									if (tile.type != 318)
									{
										goto IL_349F;
									}
									if (flag)
									{
										num19 = 0.7f;
										num20 = 0.2f;
										num21 = 0.5f;
										goto IL_349F;
									}
									num19 = 0.4f;
									num20 = 0.1f;
									num21 = 0.25f;
									goto IL_349F;
								}
							}
							else if (type2 <= 381)
							{
								if (type2 <= 350)
								{
									if (type2 == 327)
									{
										float num55 = 0.5f;
										num55 += (float)(270 - (int)Main.mouseTextColor) / 1500f;
										num55 += (float)Main.rand.Next(0, 50) * 0.0005f;
										num19 = 1f * num55;
										num20 = 0.5f * num55;
										num21 = 0.1f * num55;
										goto IL_349F;
									}
									switch (type2)
									{
									case 336:
										num19 = 0.85f;
										num20 = 0.5f;
										num21 = 0.3f;
										goto IL_349F;
									case 337:
									case 338:
									case 339:
									case 345:
									case 346:
										goto IL_349F;
									case 340:
										num19 = 0.45f;
										num20 = 1f;
										num21 = 0.45f;
										goto IL_349F;
									case 341:
										num19 = 0.4f * Main.demonTorch + 0.6f * (1f - Main.demonTorch);
										num20 = 0.35f;
										num21 = 1f * Main.demonTorch + 0.6f * (1f - Main.demonTorch);
										goto IL_349F;
									case 342:
										num19 = 0.5f;
										num20 = 0.5f;
										num21 = 1.1f;
										goto IL_349F;
									case 343:
										num19 = 0.85f;
										num20 = 0.85f;
										num21 = 0.3f;
										goto IL_349F;
									case 344:
										num19 = 0.6f;
										num20 = 1.026f;
										num21 = 0.960000038f;
										goto IL_349F;
									case 347:
										break;
									case 348:
									case 349:
										goto IL_3437;
									case 350:
									{
										double num56 = Main.time * 0.08;
										float num57 = (float)((double)(-(double)((float)Math.Cos(((int)(num56 / 6.283) % 3 == 1) ? num56 : 0.0))) * 0.1 + 0.1);
										num19 = num57;
										num20 = num57;
										num21 = num57;
										goto IL_349F;
									}
									default:
										goto IL_349F;
									}
								}
								else
								{
									switch (type2)
									{
									case 370:
										num19 = 0.32f;
										num20 = 0.16f;
										num21 = 0.12f;
										goto IL_349F;
									case 371:
										goto IL_349F;
									case 372:
										if (tile.frameX == 0)
										{
											num19 = 0.9f;
											num20 = 0.1f;
											num21 = 0.75f;
											goto IL_349F;
										}
										goto IL_349F;
									default:
										if (type2 == 381)
										{
											num19 = 0.25f;
											num20 = 0.1f;
											num21 = 0f;
											goto IL_349F;
										}
										goto IL_349F;
									}
								}
							}
							else if (type2 <= 405)
							{
								if (type2 == 390)
								{
									num19 = 0.4f;
									num20 = 0.2f;
									num21 = 0.1f;
									goto IL_349F;
								}
								if (type2 == 391)
								{
									num19 = 0.3f;
									num20 = 0.1f;
									num21 = 0.25f;
									goto IL_349F;
								}
								if (type2 == 405 && tile.frameX < 54)
								{
									float num58 = (float)Main.rand.Next(28, 42) * 0.005f;
									num58 += (float)(270 - (int)Main.mouseTextColor) / 700f;
									switch (tile.frameX / 54)
									{
									case 1:
										num19 = 0.7f;
										num20 = 1f;
										num21 = 0.5f;
										break;
									case 2:
										num19 = 0.5f * Main.demonTorch + 1f * (1f - Main.demonTorch);
										num20 = 0.3f;
										num21 = 1f * Main.demonTorch + 0.5f * (1f - Main.demonTorch);
										break;
									case 3:
										num19 = 0.45f;
										num20 = 0.75f;
										num21 = 1f;
										break;
									case 4:
										num19 = 1.15f;
										num20 = 1.15f;
										num21 = 0.5f;
										break;
									case 5:
										num19 = (float)Main.DiscoR / 255f;
										num20 = (float)Main.DiscoG / 255f;
										num21 = (float)Main.DiscoB / 255f;
										break;
									default:
										num19 = 0.9f;
										num20 = 0.3f;
										num21 = 0.1f;
										break;
									}
									num19 += num58;
									num20 += num58;
									num21 += num58;
									goto IL_349F;
								}
								goto IL_349F;
							}
							else
							{
								switch (type2)
								{
								case 415:
									num19 = 0.7f;
									num20 = 0.5f;
									num21 = 0.1f;
									goto IL_349F;
								case 416:
									num19 = 0f;
									num20 = 0.6f;
									num21 = 0.7f;
									goto IL_349F;
								case 417:
									num19 = 0.6f;
									num20 = 0.2f;
									num21 = 0.6f;
									goto IL_349F;
								case 418:
									num19 = 0.6f;
									num20 = 0.6f;
									num21 = 0.9f;
									goto IL_349F;
								default:
									if (type2 != 429)
									{
										if (type2 == 463)
										{
											num19 = 0.2f;
											num20 = 0.4f;
											num21 = 0.8f;
											goto IL_349F;
										}
										goto IL_349F;
									}
									else
									{
										int num59 = (int)(tile.frameX / 18);
										bool flag2 = num59 % 2 >= 1;
										bool flag3 = num59 % 4 >= 2;
										bool flag4 = num59 % 8 >= 4;
										bool flag5 = num59 % 16 >= 8;
										if (flag2)
										{
											num19 += 0.5f;
										}
										if (flag3)
										{
											num20 += 0.5f;
										}
										if (flag4)
										{
											num21 += 0.5f;
										}
										if (flag5)
										{
											num19 += 0.2f;
											num20 += 0.2f;
											goto IL_349F;
										}
										goto IL_349F;
									}
									break;
								}
							}
							num19 = 0.35f;
							goto IL_349F;
							IL_3420:
							num19 = 0.83f;
							num20 = 0.6f;
							num21 = 0.5f;
							goto IL_349F;
							IL_3437:
							if (tile.type != 349 || tile.frameX >= 36)
							{
								float num60 = (float)Main.rand.Next(28, 42) * 0.005f;
								num60 += (float)(270 - (int)Main.mouseTextColor) / 1000f;
								num19 = 0.1f;
								num20 = 0.2f + num60 / 2f;
								num21 = 0.7f + num60;
							}
						}
					}
					IL_349F:
					TileLoader.ModifyLight(n, num18, (int)tile.type, ref num19, ref num20, ref num21);
					if (Lighting.RGB)
					{
						if (lightingState3.r2 < num19)
						{
							lightingState3.r2 = num19;
						}
						if (lightingState3.g2 < num20)
						{
							lightingState3.g2 = num20;
						}
						if (lightingState3.b2 < num21)
						{
							lightingState3.b2 = num21;
						}
					}
					else
					{
						float num61 = (num19 + num20 + num21) / 3f;
						if (lightingState3.r2 < num61)
						{
							lightingState3.r2 = num61;
						}
					}
					if (tile.lava() && tile.liquid > 0)
					{
						if (Lighting.RGB)
						{
							float num62 = (float)(tile.liquid / byte.MaxValue) * 0.41f + 0.14f;
							num62 = 0.55f;
							num62 += (float)(270 - (int)Main.mouseTextColor) / 900f;
							if (lightingState3.r2 < num62)
							{
								lightingState3.r2 = num62;
							}
							if (lightingState3.g2 < num62)
							{
								lightingState3.g2 = num62 * 0.6f;
							}
							if (lightingState3.b2 < num62)
							{
								lightingState3.b2 = num62 * 0.2f;
							}
						}
						else
						{
							float num63 = (float)(tile.liquid / byte.MaxValue) * 0.38f + 0.08f;
							num63 += (float)(270 - (int)Main.mouseTextColor) / 2000f;
							if (lightingState3.r2 < num63)
							{
								lightingState3.r2 = num63;
							}
						}
					}
					else if (tile.liquid > 128)
					{
						lightingState3.wetLight = true;
						if (tile.honey())
						{
							lightingState3.honeyLight = true;
						}
					}
					if (lightingState3.r2 > 0f || (Lighting.RGB && (lightingState3.g2 > 0f || lightingState3.b2 > 0f)))
					{
						int num64 = n - Lighting.firstToLightX;
						int num65 = num18 - Lighting.firstToLightY;
						if (Lighting.minX > num64)
						{
							Lighting.minX = num64;
						}
						if (Lighting.maxX < num64 + 1)
						{
							Lighting.maxX = num64 + 1;
						}
						if (Lighting.minY > num65)
						{
							Lighting.minY = num65;
						}
						if (Lighting.maxY < num65 + 1)
						{
							Lighting.maxY = num65 + 1;
						}
					}
					num8 = num18;
				}
				num8 = n;
			}
			foreach (KeyValuePair<Point16, Lighting.ColorTriplet> keyValuePair in Lighting.tempLights)
			{
				int num66 = (int)keyValuePair.Key.X - Lighting.firstTileX + Lighting.offScreenTiles;
				int num67 = (int)keyValuePair.Key.Y - Lighting.firstTileY + Lighting.offScreenTiles;
				if (num66 >= 0 && num66 < Main.screenWidth / 16 + Lighting.offScreenTiles * 2 + 10 && num67 >= 0 && num67 < Main.screenHeight / 16 + Lighting.offScreenTiles * 2 + 10)
				{
					Lighting.LightingState lightingState4 = Lighting.states[num66][num67];
					if (lightingState4.r2 < keyValuePair.Value.r)
					{
						lightingState4.r2 = keyValuePair.Value.r;
					}
					if (lightingState4.g2 < keyValuePair.Value.g)
					{
						lightingState4.g2 = keyValuePair.Value.g;
					}
					if (lightingState4.b2 < keyValuePair.Value.b)
					{
						lightingState4.b2 = keyValuePair.Value.b;
					}
					if (Lighting.minX > num66)
					{
						Lighting.minX = num66;
					}
					if (Lighting.maxX < num66 + 1)
					{
						Lighting.maxX = num66 + 1;
					}
					if (Lighting.minY > num67)
					{
						Lighting.minY = num67;
					}
					if (Lighting.maxY < num67 + 1)
					{
						Lighting.maxY = num67 + 1;
					}
				}
			}
			if (!Main.gamePaused)
			{
				Lighting.tempLights.Clear();
			}
			if (screenTileCounts[27] > 0)
			{
				Main.sunflower = true;
			}
			Main.holyTiles = screenTileCounts[109] + screenTileCounts[110] + screenTileCounts[113] + screenTileCounts[117] + screenTileCounts[116] + screenTileCounts[164] + screenTileCounts[403] + screenTileCounts[402];
			Main.evilTiles = screenTileCounts[23] + screenTileCounts[24] + screenTileCounts[25] + screenTileCounts[32] + screenTileCounts[112] + screenTileCounts[163] + screenTileCounts[400] + screenTileCounts[398] + -5 * screenTileCounts[27];
			Main.bloodTiles = screenTileCounts[199] + screenTileCounts[203] + screenTileCounts[200] + screenTileCounts[401] + screenTileCounts[399] + screenTileCounts[234] + screenTileCounts[352] - 5 * screenTileCounts[27];
			Main.snowTiles = screenTileCounts[147] + screenTileCounts[148] + screenTileCounts[161] + screenTileCounts[162] + screenTileCounts[164] + screenTileCounts[163] + screenTileCounts[200];
			Main.jungleTiles = screenTileCounts[60] + screenTileCounts[61] + screenTileCounts[62] + screenTileCounts[74] + screenTileCounts[226];
			Main.shroomTiles = screenTileCounts[70] + screenTileCounts[71] + screenTileCounts[72];
			Main.meteorTiles = screenTileCounts[37];
			Main.dungeonTiles = screenTileCounts[41] + screenTileCounts[43] + screenTileCounts[44];
			Main.sandTiles = screenTileCounts[53] + screenTileCounts[112] + screenTileCounts[116] + screenTileCounts[234] + screenTileCounts[397] + screenTileCounts[398] + screenTileCounts[402] + screenTileCounts[399] + screenTileCounts[396] + screenTileCounts[400] + screenTileCounts[403] + screenTileCounts[401];
			Main.waterCandles = screenTileCounts[49];
			Main.peaceCandles = screenTileCounts[372];
			Main.partyMonoliths = screenTileCounts[455];
			if (Main.player[Main.myPlayer].accOreFinder)
			{
				Main.player[Main.myPlayer].bestOre = -1;
				for (int num68 = 0; num68 < Main.tileValue.Length; num68 = num8 + 1)
				{
					if (screenTileCounts[num68] > 0 && Main.tileValue[num68] > 0 && (Main.player[Main.myPlayer].bestOre < 0 || Main.tileValue[num68] > Main.tileValue[Main.player[Main.myPlayer].bestOre]))
					{
						Main.player[Main.myPlayer].bestOre = num68;
					}
					num8 = num68;
				}
			}
			WorldHooks.TileCountsAvailable(screenTileCounts);
			if (Main.holyTiles < 0)
			{
				Main.holyTiles = 0;
			}
			if (Main.evilTiles < 0)
			{
				Main.evilTiles = 0;
			}
			if (Main.bloodTiles < 0)
			{
				Main.bloodTiles = 0;
			}
			int holyTiles = Main.holyTiles;
			Main.holyTiles -= Main.evilTiles;
			Main.holyTiles -= Main.bloodTiles;
			Main.evilTiles -= holyTiles;
			Main.bloodTiles -= holyTiles;
			if (Main.holyTiles < 0)
			{
				Main.holyTiles = 0;
			}
			if (Main.evilTiles < 0)
			{
				Main.evilTiles = 0;
			}
			if (Main.bloodTiles < 0)
			{
				Main.bloodTiles = 0;
			}
			Lighting.minX += Lighting.firstToLightX;
			Lighting.maxX += Lighting.firstToLightX;
			Lighting.minY += Lighting.firstToLightY;
			Lighting.maxY += Lighting.firstToLightY;
			Lighting.minX7 = Lighting.minX;
			Lighting.maxX7 = Lighting.maxX;
			Lighting.minY7 = Lighting.minY;
			Lighting.maxY7 = Lighting.maxY;
			Lighting.firstTileX7 = Lighting.firstTileX;
			Lighting.lastTileX7 = Lighting.lastTileX;
			Lighting.lastTileY7 = Lighting.lastTileY;
			Lighting.firstTileY7 = Lighting.firstTileY;
			Lighting.firstToLightX7 = Lighting.firstToLightX;
			Lighting.lastToLightX7 = Lighting.lastToLightX;
			Lighting.firstToLightY7 = Lighting.firstToLightY;
			Lighting.lastToLightY7 = Lighting.lastToLightY;
			Lighting.firstToLightX27 = Lighting.firstTileX - Lighting.offScreenTiles2;
			Lighting.firstToLightY27 = Lighting.firstTileY - Lighting.offScreenTiles2;
			Lighting.lastToLightX27 = Lighting.lastTileX + Lighting.offScreenTiles2;
			Lighting.lastToLightY27 = Lighting.lastTileY + Lighting.offScreenTiles2;
			Lighting.scrX = (int)Math.Floor((double)(Main.screenPosition.X / 16f));
			Lighting.scrY = (int)Math.Floor((double)(Main.screenPosition.Y / 16f));
			Main.renderCount = 0;
			TimeLogger.LightingTime(0, stopwatch.Elapsed.TotalMilliseconds);
			Lighting.doColors();
		}

		// Token: 0x06000184 RID: 388 RVA: 0x0008C620 File Offset: 0x0008A820
		public static void doColors()
		{
			if (Lighting.lightMode < 2)
			{
				Lighting.blueWave += (float)Lighting.blueDir * 0.0001f;
				if (Lighting.blueWave > 1f)
				{
					Lighting.blueWave = 1f;
					Lighting.blueDir = -1;
				}
				else if (Lighting.blueWave < 0.97f)
				{
					Lighting.blueWave = 0.97f;
					Lighting.blueDir = 1;
				}
				if (Lighting.RGB)
				{
					Lighting.negLight = 0.91f;
					Lighting.negLight2 = 0.56f;
					Lighting.honeyLightG = 0.7f * Lighting.negLight * Lighting.blueWave;
					Lighting.honeyLightR = 0.75f * Lighting.negLight * Lighting.blueWave;
					Lighting.honeyLightB = 0.6f * Lighting.negLight * Lighting.blueWave;
					switch (Main.waterStyle)
					{
					case 0:
					case 1:
					case 7:
					case 8:
						Lighting.wetLightG = 0.96f * Lighting.negLight * Lighting.blueWave;
						Lighting.wetLightR = 0.88f * Lighting.negLight * Lighting.blueWave;
						Lighting.wetLightB = 1.015f * Lighting.negLight * Lighting.blueWave;
						break;
					case 2:
						Lighting.wetLightG = 0.85f * Lighting.negLight * Lighting.blueWave;
						Lighting.wetLightR = 0.94f * Lighting.negLight * Lighting.blueWave;
						Lighting.wetLightB = 1.01f * Lighting.negLight * Lighting.blueWave;
						break;
					case 3:
						Lighting.wetLightG = 0.95f * Lighting.negLight * Lighting.blueWave;
						Lighting.wetLightR = 0.84f * Lighting.negLight * Lighting.blueWave;
						Lighting.wetLightB = 1.015f * Lighting.negLight * Lighting.blueWave;
						break;
					case 4:
						Lighting.wetLightG = 0.86f * Lighting.negLight * Lighting.blueWave;
						Lighting.wetLightR = 0.9f * Lighting.negLight * Lighting.blueWave;
						Lighting.wetLightB = 1.01f * Lighting.negLight * Lighting.blueWave;
						break;
					case 5:
						Lighting.wetLightG = 0.99f * Lighting.negLight * Lighting.blueWave;
						Lighting.wetLightR = 0.84f * Lighting.negLight * Lighting.blueWave;
						Lighting.wetLightB = 1.01f * Lighting.negLight * Lighting.blueWave;
						break;
					case 6:
						Lighting.wetLightG = 0.98f * Lighting.negLight * Lighting.blueWave;
						Lighting.wetLightR = 0.95f * Lighting.negLight * Lighting.blueWave;
						Lighting.wetLightB = 0.85f * Lighting.negLight * Lighting.blueWave;
						break;
					case 9:
						Lighting.wetLightG = 0.88f * Lighting.negLight * Lighting.blueWave;
						Lighting.wetLightR = 1f * Lighting.negLight * Lighting.blueWave;
						Lighting.wetLightB = 0.84f * Lighting.negLight * Lighting.blueWave;
						break;
					case 10:
						Lighting.wetLightG = 1f * Lighting.negLight * Lighting.blueWave;
						Lighting.wetLightR = 0.83f * Lighting.negLight * Lighting.blueWave;
						Lighting.wetLightB = 1f * Lighting.negLight * Lighting.blueWave;
						break;
					default:
						Lighting.wetLightG = 0f;
						Lighting.wetLightR = 0f;
						Lighting.wetLightB = 0f;
						break;
					}
					WaterStyleLoader.LightColorMultiplier(Main.waterStyle, ref Lighting.wetLightR, ref Lighting.wetLightG, ref Lighting.wetLightB);
				}
				else
				{
					Lighting.negLight = 0.9f;
					Lighting.negLight2 = 0.54f;
					Lighting.wetLightR = 0.95f * Lighting.negLight * Lighting.blueWave;
				}
				if (Main.player[Main.myPlayer].nightVision)
				{
					Lighting.negLight *= 1.03f;
					Lighting.negLight2 *= 1.03f;
				}
				if (Main.player[Main.myPlayer].blind)
				{
					Lighting.negLight *= 0.95f;
					Lighting.negLight2 *= 0.95f;
				}
				if (Main.player[Main.myPlayer].blackout)
				{
					Lighting.negLight *= 0.85f;
					Lighting.negLight2 *= 0.85f;
				}
				if (Main.player[Main.myPlayer].headcovered)
				{
					Lighting.negLight *= 0.85f;
					Lighting.negLight2 *= 0.85f;
				}
				ModHooks.ModifyLightingBrightness(ref Lighting.negLight, ref Lighting.negLight2);
			}
			else
			{
				Lighting.negLight = 0.04f;
				Lighting.negLight2 = 0.16f;
				if (Main.player[Main.myPlayer].nightVision)
				{
					Lighting.negLight -= 0.013f;
					Lighting.negLight2 -= 0.04f;
				}
				if (Main.player[Main.myPlayer].blind)
				{
					Lighting.negLight += 0.03f;
					Lighting.negLight2 += 0.06f;
				}
				if (Main.player[Main.myPlayer].blackout)
				{
					Lighting.negLight += 0.09f;
					Lighting.negLight2 += 0.18f;
				}
				if (Main.player[Main.myPlayer].headcovered)
				{
					Lighting.negLight += 0.09f;
					Lighting.negLight2 += 0.18f;
				}
				ModHooks.ModifyLightingBrightness(ref Lighting.negLight, ref Lighting.negLight2);
				Lighting.wetLightR = Lighting.negLight * 1.2f;
				Lighting.wetLightG = Lighting.negLight * 1.1f;
			}
			int num;
			int num2;
			switch (Main.renderCount)
			{
			case 0:
				num = 0;
				num2 = 1;
				break;
			case 1:
				num = 1;
				num2 = 3;
				break;
			case 2:
				num = 3;
				num2 = 4;
				break;
			default:
				num = 0;
				num2 = 0;
				break;
			}
			if (Lighting.LightingThreads < 0)
			{
				Lighting.LightingThreads = 0;
			}
			if (Lighting.LightingThreads >= Environment.ProcessorCount)
			{
				Lighting.LightingThreads = Environment.ProcessorCount - 1;
			}
			int num3 = Lighting.LightingThreads;
			if (num3 > 0)
			{
				num3++;
			}
			Stopwatch stopwatch = new Stopwatch();
			for (int i = num; i < num2; i++)
			{
				stopwatch.Restart();
				switch (i)
				{
				case 0:
					Lighting.swipe.innerLoop1Start = Lighting.minY7 - Lighting.firstToLightY7;
					Lighting.swipe.innerLoop1End = Lighting.lastToLightY27 + Lighting.maxRenderCount - Lighting.firstToLightY7;
					Lighting.swipe.innerLoop2Start = Lighting.maxY7 - Lighting.firstToLightY;
					Lighting.swipe.innerLoop2End = Lighting.firstTileY7 - Lighting.maxRenderCount - Lighting.firstToLightY7;
					Lighting.swipe.outerLoopStart = Lighting.minX7 - Lighting.firstToLightX7;
					Lighting.swipe.outerLoopEnd = Lighting.maxX7 - Lighting.firstToLightX7;
					Lighting.swipe.jaggedArray = Lighting.states;
					break;
				case 1:
					Lighting.swipe.innerLoop1Start = Lighting.minX7 - Lighting.firstToLightX7;
					Lighting.swipe.innerLoop1End = Lighting.lastTileX7 + Lighting.maxRenderCount - Lighting.firstToLightX7;
					Lighting.swipe.innerLoop2Start = Lighting.maxX7 - Lighting.firstToLightX7;
					Lighting.swipe.innerLoop2End = Lighting.firstTileX7 - Lighting.maxRenderCount - Lighting.firstToLightX7;
					Lighting.swipe.outerLoopStart = Lighting.firstToLightY7 - Lighting.firstToLightY7;
					Lighting.swipe.outerLoopEnd = Lighting.lastToLightY7 - Lighting.firstToLightY7;
					Lighting.swipe.jaggedArray = Lighting.axisFlipStates;
					break;
				case 2:
					Lighting.swipe.innerLoop1Start = Lighting.firstToLightY27 - Lighting.firstToLightY7;
					Lighting.swipe.innerLoop1End = Lighting.lastTileY7 + Lighting.maxRenderCount - Lighting.firstToLightY7;
					Lighting.swipe.innerLoop2Start = Lighting.lastToLightY27 - Lighting.firstToLightY;
					Lighting.swipe.innerLoop2End = Lighting.firstTileY7 - Lighting.maxRenderCount - Lighting.firstToLightY7;
					Lighting.swipe.outerLoopStart = Lighting.firstToLightX27 - Lighting.firstToLightX7;
					Lighting.swipe.outerLoopEnd = Lighting.lastToLightX27 - Lighting.firstToLightX7;
					Lighting.swipe.jaggedArray = Lighting.states;
					break;
				case 3:
					Lighting.swipe.innerLoop1Start = Lighting.firstToLightX27 - Lighting.firstToLightX7;
					Lighting.swipe.innerLoop1End = Lighting.lastTileX7 + Lighting.maxRenderCount - Lighting.firstToLightX7;
					Lighting.swipe.innerLoop2Start = Lighting.lastToLightX27 - Lighting.firstToLightX7;
					Lighting.swipe.innerLoop2End = Lighting.firstTileX7 - Lighting.maxRenderCount - Lighting.firstToLightX7;
					Lighting.swipe.outerLoopStart = Lighting.firstToLightY27 - Lighting.firstToLightY7;
					Lighting.swipe.outerLoopEnd = Lighting.lastToLightY27 - Lighting.firstToLightY7;
					Lighting.swipe.jaggedArray = Lighting.axisFlipStates;
					break;
				}
				if (Lighting.swipe.innerLoop1Start > Lighting.swipe.innerLoop1End)
				{
					Lighting.swipe.innerLoop1Start = Lighting.swipe.innerLoop1End;
				}
				if (Lighting.swipe.innerLoop2Start < Lighting.swipe.innerLoop2End)
				{
					Lighting.swipe.innerLoop2Start = Lighting.swipe.innerLoop2End;
				}
				if (Lighting.swipe.outerLoopStart > Lighting.swipe.outerLoopEnd)
				{
					Lighting.swipe.outerLoopStart = Lighting.swipe.outerLoopEnd;
				}
				switch (Lighting.lightMode)
				{
				case 0:
					Lighting.swipe.function = new Action<Lighting.LightingSwipeData>(Lighting.doColors_Mode0_Swipe);
					break;
				case 1:
					Lighting.swipe.function = new Action<Lighting.LightingSwipeData>(Lighting.doColors_Mode1_Swipe);
					break;
				case 2:
					Lighting.swipe.function = new Action<Lighting.LightingSwipeData>(Lighting.doColors_Mode2_Swipe);
					break;
				case 3:
					Lighting.swipe.function = new Action<Lighting.LightingSwipeData>(Lighting.doColors_Mode3_Swipe);
					break;
				default:
					Lighting.swipe.function = null;
					break;
				}
				if (num3 == 0)
				{
					Lighting.swipe.function(Lighting.swipe);
				}
				else
				{
					int num4 = Lighting.swipe.outerLoopEnd - Lighting.swipe.outerLoopStart;
					int num5 = num4 / num3;
					int num6 = num4 % num3;
					int num7 = Lighting.swipe.outerLoopStart;
					Lighting.countdown.Reset(num3);
					for (int j = 0; j < num3; j++)
					{
						Lighting.LightingSwipeData lightingSwipeData = Lighting.threadSwipes[j];
						lightingSwipeData.CopyFrom(Lighting.swipe);
						lightingSwipeData.outerLoopStart = num7;
						num7 += num5;
						if (num6 > 0)
						{
							num7++;
							num6--;
						}
						lightingSwipeData.outerLoopEnd = num7;
						ThreadPool.QueueUserWorkItem(new WaitCallback(Lighting.callback_LightingSwipe), lightingSwipeData);
					}
					while (Lighting.countdown.CurrentCount != 0)
					{
					}
				}
				TimeLogger.LightingTime(i + 1, stopwatch.Elapsed.TotalMilliseconds);
			}
		}

		// Token: 0x06000185 RID: 389 RVA: 0x0008D0A4 File Offset: 0x0008B2A4
		private static void callback_LightingSwipe(object obj)
		{
			Lighting.LightingSwipeData lightingSwipeData = obj as Lighting.LightingSwipeData;
			try
			{
				lightingSwipeData.function(lightingSwipeData);
			}
			catch
			{
			}
			Lighting.countdown.Signal();
		}

		// Token: 0x06000186 RID: 390 RVA: 0x0008D0E4 File Offset: 0x0008B2E4
		private static void doColors_Mode0_Swipe(Lighting.LightingSwipeData swipeData)
		{
			try
			{
				bool flag = true;
				for (;;)
				{
					int num;
					int num2;
					int num3;
					if (flag)
					{
						num = 1;
						num2 = swipeData.innerLoop1Start;
						num3 = swipeData.innerLoop1End;
					}
					else
					{
						num = -1;
						num2 = swipeData.innerLoop2Start;
						num3 = swipeData.innerLoop2End;
					}
					int outerLoopStart = swipeData.outerLoopStart;
					int outerLoopEnd = swipeData.outerLoopEnd;
					for (int i = outerLoopStart; i < outerLoopEnd; i++)
					{
						Lighting.LightingState[] array = swipeData.jaggedArray[i];
						float num4 = 0f;
						float num5 = 0f;
						float num6 = 0f;
						int num7 = num2;
						int num8 = num3;
						int num9 = num7;
						while (num9 != num8)
						{
							Lighting.LightingState lightingState = array[num9];
							Lighting.LightingState lightingState2 = array[num9 + num];
							bool flag3;
							bool flag2 = flag3 = false;
							if (lightingState.r2 > num4)
							{
								num4 = lightingState.r2;
							}
							else if ((double)num4 <= 0.0185)
							{
								flag2 = true;
							}
							else if (lightingState.r2 < num4)
							{
								lightingState.r2 = num4;
							}
							if (!flag2 && lightingState2.r2 <= num4)
							{
								if (lightingState.stopLight)
								{
									num4 *= Lighting.negLight2;
								}
								else if (lightingState.wetLight)
								{
									if (lightingState.honeyLight)
									{
										num4 *= Lighting.honeyLightR * (float)swipeData.rand.Next(98, 100) * 0.01f;
									}
									else
									{
										num4 *= Lighting.wetLightR * (float)swipeData.rand.Next(98, 100) * 0.01f;
									}
								}
								else
								{
									num4 *= Lighting.negLight;
								}
							}
							if (lightingState.g2 > num5)
							{
								num5 = lightingState.g2;
							}
							else if ((double)num5 <= 0.0185)
							{
								flag3 = true;
							}
							else
							{
								lightingState.g2 = num5;
							}
							if (!flag3 && lightingState2.g2 <= num5)
							{
								if (lightingState.stopLight)
								{
									num5 *= Lighting.negLight2;
								}
								else if (lightingState.wetLight)
								{
									if (lightingState.honeyLight)
									{
										num5 *= Lighting.honeyLightG * (float)swipeData.rand.Next(97, 100) * 0.01f;
									}
									else
									{
										num5 *= Lighting.wetLightG * (float)swipeData.rand.Next(97, 100) * 0.01f;
									}
								}
								else
								{
									num5 *= Lighting.negLight;
								}
							}
							if (lightingState.b2 > num6)
							{
								num6 = lightingState.b2;
								goto IL_240;
							}
							if ((double)num6 > 0.0185)
							{
								lightingState.b2 = num6;
								goto IL_240;
							}
							IL_235:
							num9 += num;
							continue;
							IL_240:
							if (lightingState2.b2 >= num6)
							{
								goto IL_235;
							}
							if (lightingState.stopLight)
							{
								num6 *= Lighting.negLight2;
								goto IL_235;
							}
							if (!lightingState.wetLight)
							{
								num6 *= Lighting.negLight;
								goto IL_235;
							}
							if (lightingState.honeyLight)
							{
								num6 *= Lighting.honeyLightB * (float)swipeData.rand.Next(97, 100) * 0.01f;
								goto IL_235;
							}
							num6 *= Lighting.wetLightB * (float)swipeData.rand.Next(97, 100) * 0.01f;
							goto IL_235;
						}
					}
					if (!flag)
					{
						break;
					}
					flag = false;
				}
			}
			catch
			{
			}
		}

		// Token: 0x06000187 RID: 391 RVA: 0x0008D3FC File Offset: 0x0008B5FC
		private static void doColors_Mode1_Swipe(Lighting.LightingSwipeData swipeData)
		{
			try
			{
				bool flag = true;
				for (;;)
				{
					int num;
					int num2;
					int num3;
					if (flag)
					{
						num = 1;
						num2 = swipeData.innerLoop1Start;
						num3 = swipeData.innerLoop1End;
					}
					else
					{
						num = -1;
						num2 = swipeData.innerLoop2Start;
						num3 = swipeData.innerLoop2End;
					}
					int outerLoopStart = swipeData.outerLoopStart;
					int outerLoopEnd = swipeData.outerLoopEnd;
					for (int i = outerLoopStart; i < outerLoopEnd; i++)
					{
						Lighting.LightingState[] array = swipeData.jaggedArray[i];
						float num4 = 0f;
						int num5 = num2;
						while (num5 != num3)
						{
							Lighting.LightingState lightingState = array[num5];
							if (lightingState.r2 > num4)
							{
								num4 = lightingState.r2;
								goto IL_A6;
							}
							if ((double)num4 > 0.0185)
							{
								if (lightingState.r2 < num4)
								{
									lightingState.r2 = num4;
									goto IL_A6;
								}
								goto IL_A6;
							}
							IL_9B:
							num5 += num;
							continue;
							IL_A6:
							if (array[num5 + num].r2 > num4)
							{
								goto IL_9B;
							}
							if (lightingState.stopLight)
							{
								num4 *= Lighting.negLight2;
								goto IL_9B;
							}
							if (!lightingState.wetLight)
							{
								num4 *= Lighting.negLight;
								goto IL_9B;
							}
							if (lightingState.honeyLight)
							{
								num4 *= Lighting.honeyLightR * (float)swipeData.rand.Next(98, 100) * 0.01f;
								goto IL_9B;
							}
							num4 *= Lighting.wetLightR * (float)swipeData.rand.Next(98, 100) * 0.01f;
							goto IL_9B;
						}
					}
					if (!flag)
					{
						break;
					}
					flag = false;
				}
			}
			catch
			{
			}
		}

		// Token: 0x06000188 RID: 392 RVA: 0x0008D580 File Offset: 0x0008B780
		private static void doColors_Mode2_Swipe(Lighting.LightingSwipeData swipeData)
		{
			try
			{
				bool flag = true;
				for (;;)
				{
					int num;
					int num2;
					int num3;
					if (flag)
					{
						num = 1;
						num2 = swipeData.innerLoop1Start;
						num3 = swipeData.innerLoop1End;
					}
					else
					{
						num = -1;
						num2 = swipeData.innerLoop2Start;
						num3 = swipeData.innerLoop2End;
					}
					int outerLoopStart = swipeData.outerLoopStart;
					int outerLoopEnd = swipeData.outerLoopEnd;
					for (int i = outerLoopStart; i < outerLoopEnd; i++)
					{
						Lighting.LightingState[] array = swipeData.jaggedArray[i];
						float num4 = 0f;
						int num5 = num2;
						while (num5 != num3)
						{
							Lighting.LightingState lightingState = array[num5];
							if (lightingState.r2 > num4)
							{
								num4 = lightingState.r2;
								goto IL_90;
							}
							if (num4 > 0f)
							{
								lightingState.r2 = num4;
								goto IL_90;
							}
							IL_88:
							num5 += num;
							continue;
							IL_90:
							if (lightingState.stopLight)
							{
								num4 -= Lighting.negLight2;
								goto IL_88;
							}
							if (lightingState.wetLight)
							{
								num4 -= Lighting.wetLightR;
								goto IL_88;
							}
							num4 -= Lighting.negLight;
							goto IL_88;
						}
					}
					if (!flag)
					{
						break;
					}
					flag = false;
				}
			}
			catch
			{
			}
		}

		// Token: 0x06000189 RID: 393 RVA: 0x0008D688 File Offset: 0x0008B888
		private static void doColors_Mode3_Swipe(Lighting.LightingSwipeData swipeData)
		{
			try
			{
				bool flag = true;
				for (;;)
				{
					int num;
					int num2;
					int num3;
					if (flag)
					{
						num = 1;
						num2 = swipeData.innerLoop1Start;
						num3 = swipeData.innerLoop1End;
					}
					else
					{
						num = -1;
						num2 = swipeData.innerLoop2Start;
						num3 = swipeData.innerLoop2End;
					}
					int outerLoopStart = swipeData.outerLoopStart;
					int outerLoopEnd = swipeData.outerLoopEnd;
					for (int i = outerLoopStart; i < outerLoopEnd; i++)
					{
						Lighting.LightingState[] array = swipeData.jaggedArray[i];
						float num4 = 0f;
						float num5 = 0f;
						float num6 = 0f;
						int num7 = num2;
						while (num7 != num3)
						{
							Lighting.LightingState lightingState = array[num7];
							bool flag3;
							bool flag2 = flag3 = false;
							if (lightingState.r2 > num4)
							{
								num4 = lightingState.r2;
							}
							else if (num4 <= 0f)
							{
								flag2 = true;
							}
							else
							{
								lightingState.r2 = num4;
							}
							if (!flag2)
							{
								if (lightingState.stopLight)
								{
									num4 -= Lighting.negLight2;
								}
								else if (lightingState.wetLight)
								{
									num4 -= Lighting.wetLightR;
								}
								else
								{
									num4 -= Lighting.negLight;
								}
							}
							if (lightingState.g2 > num5)
							{
								num5 = lightingState.g2;
							}
							else if (num5 <= 0f)
							{
								flag3 = true;
							}
							else
							{
								lightingState.g2 = num5;
							}
							if (!flag3)
							{
								if (lightingState.stopLight)
								{
									num5 -= Lighting.negLight2;
								}
								else if (lightingState.wetLight)
								{
									num5 -= Lighting.wetLightG;
								}
								else
								{
									num5 -= Lighting.negLight;
								}
							}
							if (lightingState.b2 > num6)
							{
								num6 = lightingState.b2;
								goto IL_171;
							}
							if (num6 > 0f)
							{
								lightingState.b2 = num6;
								goto IL_171;
							}
							IL_169:
							num7 += num;
							continue;
							IL_171:
							if (lightingState.stopLight)
							{
								num6 -= Lighting.negLight2;
								goto IL_169;
							}
							num6 -= Lighting.negLight;
							goto IL_169;
						}
					}
					if (!flag)
					{
						break;
					}
					flag = false;
				}
			}
			catch
			{
			}
		}

		// Token: 0x0600018A RID: 394 RVA: 0x0000703B File Offset: 0x0000523B
		public static void AddLight(Vector2 position, Vector3 rgb)
		{
			Lighting.AddLight((int)(position.X / 16f), (int)(position.Y / 16f), rgb.X, rgb.Y, rgb.Z);
		}

		// Token: 0x0600018B RID: 395 RVA: 0x0000706E File Offset: 0x0000526E
		public static void AddLight(Vector2 position, float R, float G, float B)
		{
			Lighting.AddLight((int)(position.X / 16f), (int)(position.Y / 16f), R, G, B);
		}

		// Token: 0x0600018C RID: 396 RVA: 0x0008D86C File Offset: 0x0008BA6C
		public static void AddLight(int i, int j, float R, float G, float B)
		{
			if (Main.gamePaused)
			{
				return;
			}
			if (Main.netMode == 2)
			{
				return;
			}
			if (i - Lighting.firstTileX + Lighting.offScreenTiles >= 0 && i - Lighting.firstTileX + Lighting.offScreenTiles < Main.screenWidth / 16 + Lighting.offScreenTiles * 2 + 10 && j - Lighting.firstTileY + Lighting.offScreenTiles >= 0 && j - Lighting.firstTileY + Lighting.offScreenTiles < Main.screenHeight / 16 + Lighting.offScreenTiles * 2 + 10)
			{
				if (Lighting.tempLights.Count == Lighting.maxTempLights)
				{
					return;
				}
				Point16 key = new Point16(i, j);
				Lighting.ColorTriplet colorTriplet;
				if (Lighting.tempLights.TryGetValue(key, out colorTriplet))
				{
					if (Lighting.RGB)
					{
						if (colorTriplet.r < R)
						{
							colorTriplet.r = R;
						}
						if (colorTriplet.g < G)
						{
							colorTriplet.g = G;
						}
						if (colorTriplet.b < B)
						{
							colorTriplet.b = B;
						}
						Lighting.tempLights[key] = colorTriplet;
						return;
					}
					float num = (R + G + B) / 3f;
					if (colorTriplet.r < num)
					{
						Lighting.tempLights[key] = new Lighting.ColorTriplet(num);
						return;
					}
				}
				else
				{
					if (Lighting.RGB)
					{
						colorTriplet = new Lighting.ColorTriplet(R, G, B);
					}
					else
					{
						colorTriplet = new Lighting.ColorTriplet((R + G + B) / 3f);
					}
					Lighting.tempLights.Add(key, colorTriplet);
				}
			}
		}

		// Token: 0x0600018D RID: 397 RVA: 0x0008D9C8 File Offset: 0x0008BBC8
		public static void NextLightMode()
		{
			Lighting.lightCounter += 100;
			Lighting.lightMode++;
			if (Lighting.lightMode >= 4)
			{
				Lighting.lightMode = 0;
			}
			if (Lighting.lightMode == 2 || Lighting.lightMode == 0)
			{
				Main.renderCount = 0;
				Main.renderNow = true;
				Lighting.BlackOut();
			}
		}

		// Token: 0x0600018E RID: 398 RVA: 0x0008DA1C File Offset: 0x0008BC1C
		public static void BlackOut()
		{
			int num = Main.screenWidth / 16 + Lighting.offScreenTiles * 2;
			int num2 = Main.screenHeight / 16 + Lighting.offScreenTiles * 2;
			for (int i = 0; i < num; i++)
			{
				Lighting.LightingState[] array = Lighting.states[i];
				for (int j = 0; j < num2; j++)
				{
					Lighting.LightingState lightingState = array[j];
					lightingState.r = 0f;
					lightingState.g = 0f;
					lightingState.b = 0f;
				}
			}
		}

		// Token: 0x0600018F RID: 399 RVA: 0x0008DA9C File Offset: 0x0008BC9C
		public static Color GetColor(int x, int y, Color oldColor)
		{
			int num = x - Lighting.firstTileX + Lighting.offScreenTiles;
			int num2 = y - Lighting.firstTileY + Lighting.offScreenTiles;
			if (Main.gameMenu)
			{
				return oldColor;
			}
			if (num < 0 || num2 < 0 || num >= Main.screenWidth / 16 + Lighting.offScreenTiles * 2 + 10 || num2 >= Main.screenHeight / 16 + Lighting.offScreenTiles * 2 + 10)
			{
				return Color.Black;
			}
			Color white = Color.White;
			Lighting.LightingState lightingState = Lighting.states[num][num2];
			int num3 = (int)((float)oldColor.R * lightingState.r * Lighting.brightness);
			int num4 = (int)((float)oldColor.G * lightingState.g * Lighting.brightness);
			int num5 = (int)((float)oldColor.B * lightingState.b * Lighting.brightness);
			if (num3 > 255)
			{
				num3 = 255;
			}
			if (num4 > 255)
			{
				num4 = 255;
			}
			if (num5 > 255)
			{
				num5 = 255;
			}
			white.R = (byte)num3;
			white.G = (byte)num4;
			white.B = (byte)num5;
			return white;
		}

		// Token: 0x06000190 RID: 400 RVA: 0x0008DBB0 File Offset: 0x0008BDB0
		public static Color GetColor(int x, int y)
		{
			int num = x - Lighting.firstTileX + Lighting.offScreenTiles;
			int num2 = y - Lighting.firstTileY + Lighting.offScreenTiles;
			if (Main.gameMenu)
			{
				return Color.White;
			}
			if (num < 0 || num2 < 0 || num >= Main.screenWidth / 16 + Lighting.offScreenTiles * 2 + 10 || num2 >= Main.screenHeight / 16 + Lighting.offScreenTiles * 2)
			{
				return Color.Black;
			}
			Lighting.LightingState lightingState = Lighting.states[num][num2];
			int num3 = (int)(255f * lightingState.r * Lighting.brightness);
			int num4 = (int)(255f * lightingState.g * Lighting.brightness);
			int num5 = (int)(255f * lightingState.b * Lighting.brightness);
			if (num3 > 255)
			{
				num3 = 255;
			}
			if (num4 > 255)
			{
				num4 = 255;
			}
			if (num5 > 255)
			{
				num5 = 255;
			}
			Color result = new Color((int)((byte)num3), (int)((byte)num4), (int)((byte)num5), 255);
			return result;
		}

		// Token: 0x06000191 RID: 401 RVA: 0x0008DCAC File Offset: 0x0008BEAC
		public static void GetColor9Slice(int centerX, int centerY, ref Color[] slices)
		{
			int num = centerX - Lighting.firstTileX + Lighting.offScreenTiles;
			int num2 = centerY - Lighting.firstTileY + Lighting.offScreenTiles;
			if (num <= 0 || num2 <= 0 || num >= Main.screenWidth / 16 + Lighting.offScreenTiles * 2 + 10 - 1 || num2 >= Main.screenHeight / 16 + Lighting.offScreenTiles * 2 - 1)
			{
				for (int i = 0; i < 9; i++)
				{
					slices[i] = Color.Black;
				}
				return;
			}
			int num3 = 0;
			for (int j = num - 1; j <= num + 1; j++)
			{
				Lighting.LightingState[] array = Lighting.states[j];
				for (int k = num2 - 1; k <= num2 + 1; k++)
				{
					Lighting.LightingState lightingState = array[k];
					int num4 = (int)(255f * lightingState.r * Lighting.brightness);
					int num5 = (int)(255f * lightingState.g * Lighting.brightness);
					int num6 = (int)(255f * lightingState.b * Lighting.brightness);
					if (num4 > 255)
					{
						num4 = 255;
					}
					if (num5 > 255)
					{
						num5 = 255;
					}
					if (num6 > 255)
					{
						num6 = 255;
					}
					slices[num3] = new Color((int)((byte)num4), (int)((byte)num5), (int)((byte)num6), 255);
					num3 += 3;
				}
				num3 -= 8;
			}
		}

		// Token: 0x06000192 RID: 402 RVA: 0x0008DE04 File Offset: 0x0008C004
		public static Vector3 GetSubLight(Vector2 position)
		{
			Vector2 vector = position / 16f - new Vector2(0.5f, 0.5f);
			Vector2 vector2 = new Vector2(vector.X % 1f, vector.Y % 1f);
			int num = (int)vector.X - Lighting.firstTileX + Lighting.offScreenTiles;
			int num2 = (int)vector.Y - Lighting.firstTileY + Lighting.offScreenTiles;
			if (num <= 0 || num2 <= 0 || num >= Main.screenWidth / 16 + Lighting.offScreenTiles * 2 + 10 - 1 || num2 >= Main.screenHeight / 16 + Lighting.offScreenTiles * 2 - 1)
			{
				return Vector3.One;
			}
			Vector3 value = Lighting.states[num][num2].ToVector3();
			Vector3 value2 = Lighting.states[num + 1][num2].ToVector3();
			Vector3 value3 = Lighting.states[num][num2 + 1].ToVector3();
			Vector3 value4 = Lighting.states[num + 1][num2 + 1].ToVector3();
			Vector3 value5 = Vector3.Lerp(value, value2, vector2.X);
			Vector3 value6 = Vector3.Lerp(value3, value4, vector2.X);
			return Vector3.Lerp(value5, value6, vector2.Y);
		}

		// Token: 0x06000193 RID: 403 RVA: 0x0008DF2C File Offset: 0x0008C12C
		public static void GetColor4Slice_New(int centerX, int centerY, out VertexColors vertices, float scale = 1f)
		{
			int num = centerX - Lighting.firstTileX + Lighting.offScreenTiles;
			int num2 = centerY - Lighting.firstTileY + Lighting.offScreenTiles;
			if (num <= 0 || num2 <= 0 || num >= Main.screenWidth / 16 + Lighting.offScreenTiles * 2 + 10 - 1 || num2 >= Main.screenHeight / 16 + Lighting.offScreenTiles * 2 - 1)
			{
				vertices.BottomLeftColor = Color.Black;
				vertices.BottomRightColor = Color.Black;
				vertices.TopLeftColor = Color.Black;
				vertices.TopRightColor = Color.Black;
				return;
			}
			Lighting.LightingState lightingState = Lighting.states[num][num2];
			Lighting.LightingState lightingState2 = Lighting.states[num][num2 - 1];
			Lighting.LightingState lightingState3 = Lighting.states[num][num2 + 1];
			Lighting.LightingState lightingState4 = Lighting.states[num - 1][num2];
			Lighting.LightingState lightingState5 = Lighting.states[num + 1][num2];
			Lighting.LightingState lightingState6 = Lighting.states[num - 1][num2 - 1];
			Lighting.LightingState lightingState7 = Lighting.states[num + 1][num2 - 1];
			Lighting.LightingState lightingState8 = Lighting.states[num - 1][num2 + 1];
			Lighting.LightingState lightingState9 = Lighting.states[num + 1][num2 + 1];
			float num3 = Lighting.brightness * scale * 255f * 0.25f;
			float num4 = (lightingState2.r + lightingState6.r + lightingState4.r + lightingState.r) * num3;
			float num5 = (lightingState2.g + lightingState6.g + lightingState4.g + lightingState.g) * num3;
			float num6 = (lightingState2.b + lightingState6.b + lightingState4.b + lightingState.b) * num3;
			if (num4 > 255f)
			{
				num4 = 255f;
			}
			if (num5 > 255f)
			{
				num5 = 255f;
			}
			if (num6 > 255f)
			{
				num6 = 255f;
			}
			vertices.TopLeftColor = new Color((int)((byte)num4), (int)((byte)num5), (int)((byte)num6), 255);
			num4 = (lightingState2.r + lightingState7.r + lightingState5.r + lightingState.r) * num3;
			num5 = (lightingState2.g + lightingState7.g + lightingState5.g + lightingState.g) * num3;
			num6 = (lightingState2.b + lightingState7.b + lightingState5.b + lightingState.b) * num3;
			if (num4 > 255f)
			{
				num4 = 255f;
			}
			if (num5 > 255f)
			{
				num5 = 255f;
			}
			if (num6 > 255f)
			{
				num6 = 255f;
			}
			vertices.TopRightColor = new Color((int)((byte)num4), (int)((byte)num5), (int)((byte)num6), 255);
			num4 = (lightingState3.r + lightingState8.r + lightingState4.r + lightingState.r) * num3;
			num5 = (lightingState3.g + lightingState8.g + lightingState4.g + lightingState.g) * num3;
			num6 = (lightingState3.b + lightingState8.b + lightingState4.b + lightingState.b) * num3;
			if (num4 > 255f)
			{
				num4 = 255f;
			}
			if (num5 > 255f)
			{
				num5 = 255f;
			}
			if (num6 > 255f)
			{
				num6 = 255f;
			}
			vertices.BottomLeftColor = new Color((int)((byte)num4), (int)((byte)num5), (int)((byte)num6), 255);
			num4 = (lightingState3.r + lightingState9.r + lightingState5.r + lightingState.r) * num3;
			num5 = (lightingState3.g + lightingState9.g + lightingState5.g + lightingState.g) * num3;
			num6 = (lightingState3.b + lightingState9.b + lightingState5.b + lightingState.b) * num3;
			if (num4 > 255f)
			{
				num4 = 255f;
			}
			if (num5 > 255f)
			{
				num5 = 255f;
			}
			if (num6 > 255f)
			{
				num6 = 255f;
			}
			vertices.BottomRightColor = new Color((int)((byte)num4), (int)((byte)num5), (int)((byte)num6), 255);
		}

		// Token: 0x06000194 RID: 404 RVA: 0x0008E308 File Offset: 0x0008C508
		public static void GetColor4Slice_New(int centerX, int centerY, out VertexColors vertices, Color centerColor, float scale = 1f)
		{
			int num = centerX - Lighting.firstTileX + Lighting.offScreenTiles;
			int num2 = centerY - Lighting.firstTileY + Lighting.offScreenTiles;
			if (num <= 0 || num2 <= 0 || num >= Main.screenWidth / 16 + Lighting.offScreenTiles * 2 + 10 - 1 || num2 >= Main.screenHeight / 16 + Lighting.offScreenTiles * 2 - 1)
			{
				vertices.BottomLeftColor = Color.Black;
				vertices.BottomRightColor = Color.Black;
				vertices.TopLeftColor = Color.Black;
				vertices.TopRightColor = Color.Black;
				return;
			}
			float num3 = (float)centerColor.R / 255f;
			float num4 = (float)centerColor.G / 255f;
			float num5 = (float)centerColor.B / 255f;
			Lighting.LightingState lightingState = Lighting.states[num][num2 - 1];
			Lighting.LightingState lightingState2 = Lighting.states[num][num2 + 1];
			Lighting.LightingState lightingState3 = Lighting.states[num - 1][num2];
			Lighting.LightingState lightingState4 = Lighting.states[num + 1][num2];
			Lighting.LightingState lightingState5 = Lighting.states[num - 1][num2 - 1];
			Lighting.LightingState lightingState6 = Lighting.states[num + 1][num2 - 1];
			Lighting.LightingState lightingState7 = Lighting.states[num - 1][num2 + 1];
			Lighting.LightingState lightingState8 = Lighting.states[num + 1][num2 + 1];
			float num6 = Lighting.brightness * scale * 255f * 0.25f;
			float num7 = (lightingState.r + lightingState5.r + lightingState3.r + num3) * num6;
			float num8 = (lightingState.g + lightingState5.g + lightingState3.g + num4) * num6;
			float num9 = (lightingState.b + lightingState5.b + lightingState3.b + num5) * num6;
			if (num7 > 255f)
			{
				num7 = 255f;
			}
			if (num8 > 255f)
			{
				num8 = 255f;
			}
			if (num9 > 255f)
			{
				num9 = 255f;
			}
			vertices.TopLeftColor = new Color((int)((byte)num7), (int)((byte)num8), (int)((byte)num9), 255);
			num7 = (lightingState.r + lightingState6.r + lightingState4.r + num3) * num6;
			num8 = (lightingState.g + lightingState6.g + lightingState4.g + num4) * num6;
			num9 = (lightingState.b + lightingState6.b + lightingState4.b + num5) * num6;
			if (num7 > 255f)
			{
				num7 = 255f;
			}
			if (num8 > 255f)
			{
				num8 = 255f;
			}
			if (num9 > 255f)
			{
				num9 = 255f;
			}
			vertices.TopRightColor = new Color((int)((byte)num7), (int)((byte)num8), (int)((byte)num9), 255);
			num7 = (lightingState2.r + lightingState7.r + lightingState3.r + num3) * num6;
			num8 = (lightingState2.g + lightingState7.g + lightingState3.g + num4) * num6;
			num9 = (lightingState2.b + lightingState7.b + lightingState3.b + num5) * num6;
			if (num7 > 255f)
			{
				num7 = 255f;
			}
			if (num8 > 255f)
			{
				num8 = 255f;
			}
			if (num9 > 255f)
			{
				num9 = 255f;
			}
			vertices.BottomLeftColor = new Color((int)((byte)num7), (int)((byte)num8), (int)((byte)num9), 255);
			num7 = (lightingState2.r + lightingState8.r + lightingState4.r + num3) * num6;
			num8 = (lightingState2.g + lightingState8.g + lightingState4.g + num4) * num6;
			num9 = (lightingState2.b + lightingState8.b + lightingState4.b + num5) * num6;
			if (num7 > 255f)
			{
				num7 = 255f;
			}
			if (num8 > 255f)
			{
				num8 = 255f;
			}
			if (num9 > 255f)
			{
				num9 = 255f;
			}
			vertices.BottomRightColor = new Color((int)((byte)num7), (int)((byte)num8), (int)((byte)num9), 255);
		}

		// Token: 0x06000195 RID: 405 RVA: 0x0008E6D8 File Offset: 0x0008C8D8
		public static void GetColor4Slice(int centerX, int centerY, ref Color[] slices)
		{
			int i = centerX - Lighting.firstTileX + Lighting.offScreenTiles;
			int num = centerY - Lighting.firstTileY + Lighting.offScreenTiles;
			if (i <= 0 || num <= 0 || i >= Main.screenWidth / 16 + Lighting.offScreenTiles * 2 + 10 - 1 || num >= Main.screenHeight / 16 + Lighting.offScreenTiles * 2 - 1)
			{
				for (i = 0; i < 4; i++)
				{
					slices[i] = Color.Black;
				}
				return;
			}
			Lighting.LightingState lightingState = Lighting.states[i][num - 1];
			Lighting.LightingState lightingState2 = Lighting.states[i][num + 1];
			Lighting.LightingState lightingState3 = Lighting.states[i - 1][num];
			Lighting.LightingState lightingState4 = Lighting.states[i + 1][num];
			float num2 = lightingState.r + lightingState.g + lightingState.b;
			float num3 = lightingState2.r + lightingState2.g + lightingState2.b;
			float num4 = lightingState4.r + lightingState4.g + lightingState4.b;
			float num5 = lightingState3.r + lightingState3.g + lightingState3.b;
			if (num2 >= num5)
			{
				int num6 = (int)(255f * lightingState3.r * Lighting.brightness);
				int num7 = (int)(255f * lightingState3.g * Lighting.brightness);
				int num8 = (int)(255f * lightingState3.b * Lighting.brightness);
				if (num6 > 255)
				{
					num6 = 255;
				}
				if (num7 > 255)
				{
					num7 = 255;
				}
				if (num8 > 255)
				{
					num8 = 255;
				}
				slices[0] = new Color((int)((byte)num6), (int)((byte)num7), (int)((byte)num8), 255);
			}
			else
			{
				int num9 = (int)(255f * lightingState.r * Lighting.brightness);
				int num10 = (int)(255f * lightingState.g * Lighting.brightness);
				int num11 = (int)(255f * lightingState.b * Lighting.brightness);
				if (num9 > 255)
				{
					num9 = 255;
				}
				if (num10 > 255)
				{
					num10 = 255;
				}
				if (num11 > 255)
				{
					num11 = 255;
				}
				slices[0] = new Color((int)((byte)num9), (int)((byte)num10), (int)((byte)num11), 255);
			}
			if (num2 >= num4)
			{
				int num12 = (int)(255f * lightingState4.r * Lighting.brightness);
				int num13 = (int)(255f * lightingState4.g * Lighting.brightness);
				int num14 = (int)(255f * lightingState4.b * Lighting.brightness);
				if (num12 > 255)
				{
					num12 = 255;
				}
				if (num13 > 255)
				{
					num13 = 255;
				}
				if (num14 > 255)
				{
					num14 = 255;
				}
				slices[1] = new Color((int)((byte)num12), (int)((byte)num13), (int)((byte)num14), 255);
			}
			else
			{
				int num15 = (int)(255f * lightingState.r * Lighting.brightness);
				int num16 = (int)(255f * lightingState.g * Lighting.brightness);
				int num17 = (int)(255f * lightingState.b * Lighting.brightness);
				if (num15 > 255)
				{
					num15 = 255;
				}
				if (num16 > 255)
				{
					num16 = 255;
				}
				if (num17 > 255)
				{
					num17 = 255;
				}
				slices[1] = new Color((int)((byte)num15), (int)((byte)num16), (int)((byte)num17), 255);
			}
			if (num3 >= num5)
			{
				int num18 = (int)(255f * lightingState3.r * Lighting.brightness);
				int num19 = (int)(255f * lightingState3.g * Lighting.brightness);
				int num20 = (int)(255f * lightingState3.b * Lighting.brightness);
				if (num18 > 255)
				{
					num18 = 255;
				}
				if (num19 > 255)
				{
					num19 = 255;
				}
				if (num20 > 255)
				{
					num20 = 255;
				}
				slices[2] = new Color((int)((byte)num18), (int)((byte)num19), (int)((byte)num20), 255);
			}
			else
			{
				int num21 = (int)(255f * lightingState2.r * Lighting.brightness);
				int num22 = (int)(255f * lightingState2.g * Lighting.brightness);
				int num23 = (int)(255f * lightingState2.b * Lighting.brightness);
				if (num21 > 255)
				{
					num21 = 255;
				}
				if (num22 > 255)
				{
					num22 = 255;
				}
				if (num23 > 255)
				{
					num23 = 255;
				}
				slices[2] = new Color((int)((byte)num21), (int)((byte)num22), (int)((byte)num23), 255);
			}
			if (num3 >= num4)
			{
				int num24 = (int)(255f * lightingState4.r * Lighting.brightness);
				int num25 = (int)(255f * lightingState4.g * Lighting.brightness);
				int num26 = (int)(255f * lightingState4.b * Lighting.brightness);
				if (num24 > 255)
				{
					num24 = 255;
				}
				if (num25 > 255)
				{
					num25 = 255;
				}
				if (num26 > 255)
				{
					num26 = 255;
				}
				slices[3] = new Color((int)((byte)num24), (int)((byte)num25), (int)((byte)num26), 255);
				return;
			}
			int num27 = (int)(255f * lightingState2.r * Lighting.brightness);
			int num28 = (int)(255f * lightingState2.g * Lighting.brightness);
			int num29 = (int)(255f * lightingState2.b * Lighting.brightness);
			if (num27 > 255)
			{
				num27 = 255;
			}
			if (num28 > 255)
			{
				num28 = 255;
			}
			if (num29 > 255)
			{
				num29 = 255;
			}
			slices[3] = new Color((int)((byte)num27), (int)((byte)num28), (int)((byte)num29), 255);
		}

		// Token: 0x06000196 RID: 406 RVA: 0x0008EC70 File Offset: 0x0008CE70
		public static Color GetBlackness(int x, int y)
		{
			int num = x - Lighting.firstTileX + Lighting.offScreenTiles;
			int num2 = y - Lighting.firstTileY + Lighting.offScreenTiles;
			if (num < 0 || num2 < 0 || num >= Main.screenWidth / 16 + Lighting.offScreenTiles * 2 + 10 || num2 >= Main.screenHeight / 16 + Lighting.offScreenTiles * 2 + 10)
			{
				return Color.Black;
			}
			Color result = new Color(0, 0, 0, (int)((byte)(255f - 255f * Lighting.states[num][num2].r)));
			return result;
		}

		// Token: 0x06000197 RID: 407 RVA: 0x0008ECFC File Offset: 0x0008CEFC
		public static float Brightness(int x, int y)
		{
			int num = x - Lighting.firstTileX + Lighting.offScreenTiles;
			int num2 = y - Lighting.firstTileY + Lighting.offScreenTiles;
			if (num < 0 || num2 < 0 || num >= Main.screenWidth / 16 + Lighting.offScreenTiles * 2 + 10 || num2 >= Main.screenHeight / 16 + Lighting.offScreenTiles * 2 + 10)
			{
				return 0f;
			}
			Lighting.LightingState lightingState = Lighting.states[num][num2];
			return Lighting.brightness * (lightingState.r + lightingState.g + lightingState.b) / 3f;
		}

		// Token: 0x06000198 RID: 408 RVA: 0x0008ED8C File Offset: 0x0008CF8C
		public static float BrightnessAverage(int x, int y, int width, int height)
		{
			int num = x - Lighting.firstTileX + Lighting.offScreenTiles;
			int num2 = y - Lighting.firstTileY + Lighting.offScreenTiles;
			int num3 = num + width;
			int num4 = num2 + height;
			if (num < 0)
			{
				num = 0;
			}
			if (num2 < 0)
			{
				num2 = 0;
			}
			if (num3 >= Main.screenWidth / 16 + Lighting.offScreenTiles * 2 + 10)
			{
				num3 = Main.screenWidth / 16 + Lighting.offScreenTiles * 2 + 10;
			}
			if (num4 >= Main.screenHeight / 16 + Lighting.offScreenTiles * 2 + 10)
			{
				num4 = Main.screenHeight / 16 + Lighting.offScreenTiles * 2 + 10;
			}
			float num5 = 0f;
			float num6 = 0f;
			for (int i = num; i < num3; i++)
			{
				for (int j = num2; j < num4; j++)
				{
					num5 += 1f;
					Lighting.LightingState lightingState = Lighting.states[i][j];
					num6 += (lightingState.r + lightingState.g + lightingState.b) / 3f;
				}
			}
			if (num5 == 0f)
			{
				return 0f;
			}
			return num6 / num5;
		}

		// Token: 0x04000194 RID: 404
		public static int maxRenderCount = 4;

		// Token: 0x04000195 RID: 405
		public static float brightness = 1f;

		// Token: 0x04000196 RID: 406
		public static float defBrightness = 1f;

		// Token: 0x04000197 RID: 407
		public static int lightMode = 0;

		// Token: 0x04000198 RID: 408
		public static bool RGB = true;

		// Token: 0x04000199 RID: 409
		private static float oldSkyColor = 0f;

		// Token: 0x0400019A RID: 410
		private static float skyColor = 0f;

		// Token: 0x0400019B RID: 411
		private static int lightCounter = 0;

		// Token: 0x0400019C RID: 412
		public static int offScreenTiles = 45;

		// Token: 0x0400019D RID: 413
		public static int offScreenTiles2 = 35;

		// Token: 0x0400019E RID: 414
		private static int firstTileX;

		// Token: 0x0400019F RID: 415
		private static int lastTileX;

		// Token: 0x040001A0 RID: 416
		private static int firstTileY;

		// Token: 0x040001A1 RID: 417
		private static int lastTileY;

		// Token: 0x040001A2 RID: 418
		public static int LightingThreads = 0;

		// Token: 0x040001A3 RID: 419
		private static Lighting.LightingState[][] states;

		// Token: 0x040001A4 RID: 420
		private static Lighting.LightingState[][] axisFlipStates;

		// Token: 0x040001A5 RID: 421
		private static Lighting.LightingSwipeData swipe;

		// Token: 0x040001A6 RID: 422
		private static Lighting.LightingSwipeData[] threadSwipes;

		// Token: 0x040001A7 RID: 423
		private static CountdownEvent countdown;

		// Token: 0x040001A8 RID: 424
		public static int scrX;

		// Token: 0x040001A9 RID: 425
		public static int scrY;

		// Token: 0x040001AA RID: 426
		public static int minX;

		// Token: 0x040001AB RID: 427
		public static int maxX;

		// Token: 0x040001AC RID: 428
		public static int minY;

		// Token: 0x040001AD RID: 429
		public static int maxY;

		// Token: 0x040001AE RID: 430
		private static int maxTempLights = 2000;

		// Token: 0x040001AF RID: 431
		private static Dictionary<Point16, Lighting.ColorTriplet> tempLights;

		// Token: 0x040001B0 RID: 432
		private static int firstToLightX;

		// Token: 0x040001B1 RID: 433
		private static int firstToLightY;

		// Token: 0x040001B2 RID: 434
		private static int lastToLightX;

		// Token: 0x040001B3 RID: 435
		private static int lastToLightY;

		// Token: 0x040001B4 RID: 436
		internal static float negLight = 0.04f;

		// Token: 0x040001B5 RID: 437
		private static float negLight2 = 0.16f;

		// Token: 0x040001B6 RID: 438
		private static float wetLightR = 0.16f;

		// Token: 0x040001B7 RID: 439
		private static float wetLightG = 0.16f;

		// Token: 0x040001B8 RID: 440
		private static float wetLightB = 0.16f;

		// Token: 0x040001B9 RID: 441
		private static float honeyLightR = 0.16f;

		// Token: 0x040001BA RID: 442
		private static float honeyLightG = 0.16f;

		// Token: 0x040001BB RID: 443
		private static float honeyLightB = 0.16f;

		// Token: 0x040001BC RID: 444
		internal static float blueWave = 1f;

		// Token: 0x040001BD RID: 445
		private static int blueDir = 1;

		// Token: 0x040001BE RID: 446
		private static int minX7;

		// Token: 0x040001BF RID: 447
		private static int maxX7;

		// Token: 0x040001C0 RID: 448
		private static int minY7;

		// Token: 0x040001C1 RID: 449
		private static int maxY7;

		// Token: 0x040001C2 RID: 450
		private static int firstTileX7;

		// Token: 0x040001C3 RID: 451
		private static int lastTileX7;

		// Token: 0x040001C4 RID: 452
		private static int lastTileY7;

		// Token: 0x040001C5 RID: 453
		private static int firstTileY7;

		// Token: 0x040001C6 RID: 454
		private static int firstToLightX7;

		// Token: 0x040001C7 RID: 455
		private static int lastToLightX7;

		// Token: 0x040001C8 RID: 456
		private static int firstToLightY7;

		// Token: 0x040001C9 RID: 457
		private static int lastToLightY7;

		// Token: 0x040001CA RID: 458
		private static int firstToLightX27;

		// Token: 0x040001CB RID: 459
		private static int lastToLightX27;

		// Token: 0x040001CC RID: 460
		private static int firstToLightY27;

		// Token: 0x040001CD RID: 461
		private static int lastToLightY27;

		// Token: 0x02000021 RID: 33
		private class LightingSwipeData
		{
			// Token: 0x0600019B RID: 411 RVA: 0x0008EF64 File Offset: 0x0008D164
			public LightingSwipeData()
			{
				this.innerLoop1Start = 0;
				this.outerLoopStart = 0;
				this.innerLoop1End = 0;
				this.outerLoopEnd = 0;
				this.innerLoop2Start = 0;
				this.innerLoop2End = 0;
				this.function = null;
				this.rand = new UnifiedRandom();
			}

			// Token: 0x0600019C RID: 412 RVA: 0x0008EFB4 File Offset: 0x0008D1B4
			public void CopyFrom(Lighting.LightingSwipeData from)
			{
				this.innerLoop1Start = from.innerLoop1Start;
				this.outerLoopStart = from.outerLoopStart;
				this.innerLoop1End = from.innerLoop1End;
				this.outerLoopEnd = from.outerLoopEnd;
				this.innerLoop2Start = from.innerLoop2Start;
				this.innerLoop2End = from.innerLoop2End;
				this.function = from.function;
				this.jaggedArray = from.jaggedArray;
			}

			// Token: 0x040001CE RID: 462
			public int outerLoopStart;

			// Token: 0x040001CF RID: 463
			public int outerLoopEnd;

			// Token: 0x040001D0 RID: 464
			public int innerLoop1Start;

			// Token: 0x040001D1 RID: 465
			public int innerLoop1End;

			// Token: 0x040001D2 RID: 466
			public int innerLoop2Start;

			// Token: 0x040001D3 RID: 467
			public int innerLoop2End;

			// Token: 0x040001D4 RID: 468
			public UnifiedRandom rand;

			// Token: 0x040001D5 RID: 469
			public Action<Lighting.LightingSwipeData> function;

			// Token: 0x040001D6 RID: 470
			public Lighting.LightingState[][] jaggedArray;
		}

		// Token: 0x02000022 RID: 34
		private class LightingState
		{
			// Token: 0x0600019D RID: 413 RVA: 0x00007092 File Offset: 0x00005292
			public Vector3 ToVector3()
			{
				return new Vector3(this.r, this.g, this.b);
			}

			// Token: 0x040001D7 RID: 471
			public float r;

			// Token: 0x040001D8 RID: 472
			public float r2;

			// Token: 0x040001D9 RID: 473
			public float g;

			// Token: 0x040001DA RID: 474
			public float g2;

			// Token: 0x040001DB RID: 475
			public float b;

			// Token: 0x040001DC RID: 476
			public float b2;

			// Token: 0x040001DD RID: 477
			public bool stopLight;

			// Token: 0x040001DE RID: 478
			public bool wetLight;

			// Token: 0x040001DF RID: 479
			public bool honeyLight;
		}

		// Token: 0x02000023 RID: 35
		private struct ColorTriplet
		{
			// Token: 0x0600019F RID: 415 RVA: 0x000070AB File Offset: 0x000052AB
			public ColorTriplet(float R, float G, float B)
			{
				this.r = R;
				this.g = G;
				this.b = B;
			}

			// Token: 0x060001A0 RID: 416 RVA: 0x000070C2 File Offset: 0x000052C2
			public ColorTriplet(float averageColor)
			{
				this.b = averageColor;
				this.g = averageColor;
				this.r = averageColor;
			}

			// Token: 0x040001E0 RID: 480
			public float r;

			// Token: 0x040001E1 RID: 481
			public float g;

			// Token: 0x040001E2 RID: 482
			public float b;
		}
	}
}
